Skip to main content
Cheena12
Inspiring
July 30, 2019
Answered

How to program button to execute sequence of commands

  • July 30, 2019
  • 1 reply
  • 2029 views

Not sure if this is even possible but here goes...

I would like to program a button for a user to push in order to closeout their form and ready it for processing. The sequence of events I would like would be as follows:

1) Check that all required fields have been completed; if not, allow user to go back and complete missing fields

After all required fields have been completed...

2) Set all fields to read only

3) Add three fields

4) Execute menu item Save As

5) App Alert informing them that their document is ready

I think I have the pieces for each step, I just don't know how (or if it's even possible) to join all these things together.  Any help would be appreciated.

Checking required fields:

var emptyFields = []; 

for (var i=0; i<this.numFields; i++) { 

    var f= this.getField(this.getNthFieldName(i)); 

    if (f!=null && f.type!="button" && f.required && f.display==display.visible) { 

        if (f.valueAsString==f.defaultValue) { 

            f.strokeColor = color.red; 

            emptyFields.push(f.name); 

        } else { 

          f.strokeColor = color.transparent; 

        } 

    } 

  if (emptyFields.length>0) { 

    app.alert({cMsg:"YOU MUST COMPLETE THE FOLLOWING SECTIONS:\n" + emptyFields.join("\n"),nIcon:0,cTitle:"Required Information Missing"});

Setting all fields to read only:

var oField;

for (var i = 0; i < this.numFields; i++) {

oField = this.getField(this.getNthFieldName(i)).readonly = true;

Add three fields:

this.addField("TextField1", "text", 0, [107,205,198,191]);

this.addField("TextField2", "text", 0, [260,205,365,191]);

this.addField("TextField3", "text", 0, [440,205,500,191]);

Executing menu item Save As:

app.execMenuItem("SaveAs");

App Alert:

app.alert({cMsg:"Your form has been saved successfully and is ready for DocuSign submission.",nIcon:3,nType:0,cTitle:"Finished"});

This topic has been closed for replies.
Correct answer Cheena12

I kept at it and found a workaround to my double layer of required fields. My solution is below in case it can help anyone else.

Thank you very much to Test Screen Name​ for the initial guidance.

*Important to note that I removed my "Action" fields as required.

var a = getField("Action").valueAsString;
if(a==="Off"){
   app.alert({cMsg:"YOU MUST SELECT AN ACTION.",nIcon:0,cTitle:"Required Information Missing"});
}else{
var emptyFields = []; 
for (var i=0; i<this.numFields; i++) { 
    var f= this.getField(this.getNthFieldName(i)); 
    if (f!=null && f.type!="button" && f.required && f.display==display.visible) { 
        if (f.valueAsString==f.defaultValue) { 
            f.strokeColor = color.red; 
            emptyFields.push(f.name); 
        } else { 
          f.strokeColor = color.transparent; 
        } 
    } 

  if (emptyFields.length>0) { 
    app.alert({cMsg:"THE FOLLOWING SECTIONS ARE REQUIRED:\n" + emptyFields.join("\n"),nIcon:0,cTitle:"Required Information Missing"});
} else {
{
var oField;
for (var i = 0; i < this.numFields; i++)
oField = this.getField(this.getNthFieldName(i)).readonly = true;

this.addField("TextField1", "text", 0, [107,205,198,191]);
this.addField("TextField2", "text", 0, [260,205,365,191]);
this.addField("TextField3", "text", 0, [440,205,500,191]);

app.alert({cMsg:"After you save your form, proceed to DocuSign to finish processing your request.",nIcon:3,nType:0,cTitle:"Finished"});

app.execMenuItem("SaveAs");
}}}

1 reply

Legend
July 30, 2019

In general, you just make a longer script which does all of these things in turn.

However, you need to consider carefully that you do not want to do steps 2-5 if the test in step 1 fails.

(You also have no way of knowing that the save succeeded; the message doesn't seem right, or necessary. Surely if the user does the save, they know the file is ready, and if they don't, then they know it isn't. Or consider swapping steps 4 and 5 with a message like Now you will save the file, after saving it is ready...).

To make steps 2-5 conditional, add to step 1, following

if ( some test )

some message

else

{

}

And puts steps 2-5 all inside the

{

}

part

Cheena12
Cheena12Author
Inspiring
July 30, 2019

Thank you for your prompt response. I played around with the script based on your suggestions and directives (below) and it worked...for the most part. But I ran into a snag: my form has two levels of required fields. The first level dictates that the user select one of four requested actions. Once an action has been selected, that triggers the required fields related to that action.

So, when I tested the script below with no action was selected, it did send me back to select one. But once I selected an action, it did not prompt me to fix the related required fields and instead continued through the rest of the conditions.

Any ideas?

~~~~~~~

var emptyFields = []; 
for (var i=0; i<this.numFields; i++) { 
    var f= this.getField(this.getNthFieldName(i)); 
    if (f!=null && f.type!="button" && f.required && f.display==display.visible) { 
        if (f.valueAsString==f.defaultValue) { 
            f.strokeColor = color.red; 
            emptyFields.push(f.name); 
        } else { 
          f.strokeColor = color.transparent; 
        } 
    } 

  if (emptyFields.length>0) { 
    app.alert({cMsg:"THE FOLLOWING SECTIONS ARE REQUIRED:\n" + emptyFields.join("\n"),nIcon:0,cTitle:"Required Information Missing"});
} else {
{
var oField;
for (var i = 0; i < this.numFields; i++)
oField = this.getField(this.getNthFieldName(i)).readonly = true;

this.addField("TextField1", "text", 0, [107,205,198,191]);
this.addField("TextField2", "text", 0, [260,205,365,191]);
this.addField("TextField3", "text", 0, [440,205,500,191]);

app.alert({cMsg:"After you save your form, proceed to DocuSign to finish processing your request.",nIcon:3,nType:0,cTitle:"Finished"});

app.execMenuItem("SaveAs");
}}

Bernd Alheit
Community Expert
Community Expert
July 30, 2019

What does you use at the requested actions?