How to programmatically save form using value from a field

C

Caeanis

Instead of getting the save as dialog each time, I would like to write a
script for a button on the form that saves the xml using the name from a
designated field. Is there a way to do this?

Thank you!
 
K

kookie

here is the jscript code I have used by combining multiple fields and
removing spaces. I am using it in the OnSaveRequest But i am sure it can be
modified to fit your needs.

function XDocument::OnSaveRequest(eventObj)
{

var strContentTypeRpt =
XDocument.DOM.selectSingleNode("/my:myFields/my:TypeGroup/my:ContentTypeRpt");
var strContentTypeRole =
XDocument.DOM.selectSingleNode("/my:myFields/my:TypeGroup/my:ContentTypeRole");
var strSystemName =
XDocument.DOM.selectSingleNode("/my:myFields/my:TypeGroup/my:SystemNameSect/my:SystemName");
var strMnPName =
XDocument.DOM.selectSingleNode("/my:myFields/my:MnPName").text;
var strRegion =
XDocument.DOM.selectSingleNode("/my:myFields/my:Region").text;
//var strRole =
XDocument.DOM.selectSingleNode("/my:myFields/my:Role").text;
var strCountry =
XDocument.DOM.selectSingleNode("/my:myFields/my:Country");
var strContent =
XDocument.DOM.selectSingleNode("/my:myFields/my:ContentType");
//var strType =
XDocument.DOM.selectSingleNode("/my:myFields/my:TypeGroup/my:ContentTypeTotal");
var StrCoun
var strType2
var strSN
var CTRole

if (strContent.text != "M&P") {
strType2 = "";
}
else {
strType2 = strContentTypeRpt.text + strContentTypeRole.text;
}
////////////Compensate for Blank Country field/////////////
if(strRegion != "Global"){
if(strCountry.text != "Choose Country"){ // ||(strCountry.text != "Choose
Country")) {
StrCoun = "_" + strCountry.text;
//XDocument.UI.Alert(StrCoun);
}
else {
StrCoun = "";
//XDocument.UI.Alert(StrCoun);
}
}
else {
StrCoun = "";
//XDocument.UI.Alert(StrCoun);
}
/////////////Compensate for Blank System Name field////////////////
if(strSystemName.text == "") {
strSN = "";
}
else {
strSN = "_" + strSystemName.text;
}
/////////////////////////////////////////////////////////////////
if(strContentTypeRole.test != "") {
strCTRole = "_" + strContentTypeRole.text;
}
else {
strCTRole = "";
}
/////////////////////////////////////////////////////////////////
var blank = " ";

var nameSum = countSpaces(strMnPName);
for(var icount = 0; icount < nameSum; icount++) {
strMnPName = strMnPName.replace(blank,"");

}


var strURI = XDocument.Solution.URI; //template path
var strFormLib = strURI.substr(0, strURI.indexOf("Forms/template.xsn"));

if (XDocument.IsNew == true || eventObj.IsSaveAs == false)
{

if (eventObj.IsSaveAs == true)
{

XDocument.UI.SetSaveAsDialogLocation(strFormLib);
//XDocument.UI.SetSaveAsDialogFileName(strMnPName + "_" +
strType2 + "_" + strRegion + StrCoun);
XDocument.UI.SetSaveAsDialogFileName(strMnPName + strSN +
strCTRole + "_" + strRegion + StrCoun);
removeRE1();
}
eventObj.IsCancelled = eventObj.PerformSaveOperation();
eventObj.ReturnStatus = true;
}
/*
else
{
XDocument.UI.Alert("The 'Save As' functionality is disabled for
forms that are not new.");
}
*/
else if (XDocument.IsNew == false)
{

if (eventObj.IsSaveAs == true)
{



XDocument.UI.SetSaveAsDialogLocation(strFormLib);
XDocument.UI.SetSaveAsDialogFileName(strMnPName + strSN +
strCTRole + "_" + strRegion + StrCoun);
removeRE1();
}
eventObj.IsCancelled = eventObj.PerformSaveOperation();
eventObj.ReturnStatus = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top