Skip to main content
Inspiring
July 21, 2020
Answered

buttonSetCaption to change based on user input variable

  • July 21, 2020
  • 1 reply
  • 746 views

I am currently working on a form that spawns pages and adds the serial number to each page and changes the Button name to the serial number the technician types in.  It works the way I expected, but changing the buttonSetCaption command using a variable also generates an error.  This was liveable but the technicians have requested that we add a way to change the serial number within the document instead of having to create a whole new form. This has become problematic and I can not find a solution online or in any of the forums - any help/insight would be greatly appreciated. Here is the code I have so far:

// If button is Clicked and the hidden check box is not checked - the Analyzer1 check-off pages will be spawned;

var cb2 = this.getField("CB2").value;

// Assign Templates to be spawned a variable so they may be recalled;
var a1a = this.getTemplate("Analyzer1A");
var a1b = this.getTemplate("Analyzer1B");
var a1c = this.getTemplate("Analyzer1C");
var a1d = this.getTemplate("Analyzer1D");

if (cb2 !== "Yes"){

var resp1 = app.response({cQuestion:"Enter The Analyzer Serial Number.", cTitle:"H2S Analyzer Documentation", cLabel:"H2S Analyzer #:"});

if ((resp1 === null)||(resp1 ==="")){

this.getField("Anal1").ButtonSetCaption("Analyzer 1");
}
else{

a1a.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1b.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1c.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1d.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});

this.getField("CB2").checkThisBox(0,true);

// buttonSetCaption placed at end due to error that stops code from running.  

this.getField("Anal1").buttonSetCaption(resp1).valueAsString;
}}

else{

var nser1 = app.alert ({cMsg:"Documentation For Analyzer 1 Has Already Been Created.\n\n" + "Do you wish to Change the Analyzer Serial Number?",nIcon:2,nType:2 });
// User Pressed Yes
if(nser1 === 4){
var nresp1 = app.response({cQuestion:"Enter The Analyzer Serial Number.", cTitle:"H2S Analyzer Documentation", cLabel:"H2S Analyzer #:"});
nresp1 = resp1;
this.getField("Anal1").buttonSetCaption(resp1).valueAsString;
}
}

This topic has been closed for replies.
Correct answer Bernd Alheit

Yes, when you use:

f.buttonSetCaption(resp1);

 

1 reply

Bernd Alheit
Community Expert
Community Expert
July 21, 2020

Example:

var f = this.getField("myButton");

f.buttonSetCaption("Hello"); 

DuquetteAuthor
Inspiring
July 21, 2020

Thank You Bernd for the prompt reply. Not sure if I understand - will this allow the caption on the button to be changed to the serial number the technician types in the app.response field without creating an error?

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
July 21, 2020

Yes, when you use:

f.buttonSetCaption(resp1);