Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Prompter class inside function
- This topic has 3 replies, 2 voices, and was last updated 2 years, 4 months ago by Daniel Leu.
-
AuthorPosts
-
August 22, 2022 at 2:06 PM #47801
Bob WilliamsParticipantThis is likely just my JavaScript ignorance shining through, but I’m trying to use the
Prompter
class for the first time. My code works fine if I plop it into the global scope, but if I try to wrap it in a function, the variables never get filled in. I’ve also tried wrapping it inside a class method (passingthis.xxx
as the variables to fill in), but that doesn’t work, either.Here’s my code:
// function getCopyInformation() { var noteRowNumber; var toRecordId; var preserveSorter; var prompterResultHandler = function (result) { if (result === true) { console.log('noteRowNumber: ' + noteRowNumber); console.log('toRecordId: ' + toRecordId); console.log('preserveSorter: ' + preserveSorter); } else { console.log('Canceled'); } }; let prompter = Prompter.new(); prompter.cancelButtonTitle = 'Cancel'; prompter.continueButtonTitle = 'Copy'; prompter.addParameter('Note row number: ', 'noteRowNumber') .addParameter('Target record ID: ', 'toRecordId') .addParameter('Preserve sorter value? ', 'preserveSorter', 'popup', ['Yes', 'No']) .show('Where do you want to copy the note?', prompterResultHandler); // } // var destination = getCopyInformation();
So run like this, it works. But if I uncomment the three commented lines, the three variables show as undefined (though
result
does still get set properly, so the log calls are still run).Any suggestions?
August 23, 2022 at 8:07 AM #47806
Daniel LeuParticipantYeah, the variables the prompter access’ need to be in the global scope:
var noteRowNumber; var toRecordId; var preserveSorter; var prompterResultHandler = function (result) { if (result === true) { console.log('noteRowNumber: ' + noteRowNumber); console.log('toRecordId: ' + toRecordId); console.log('preserveSorter: ' + preserveSorter); } else { console.log('Canceled'); } }; function getCopyInformation() { let prompter = Prompter.new(); prompter.cancelButtonTitle = 'Cancel'; prompter.continueButtonTitle = 'Copy'; prompter.addParameter('Note row number: ', 'noteRowNumber') .addParameter('Target record ID: ', 'toRecordId') .addParameter('Preserve sorter value? ', 'preserveSorter', 'popup', ['Yes', 'No']) .show('Where do you want to copy the note?', prompterResultHandler); } var destination = getCopyInformation();
August 23, 2022 at 8:59 AM #47807
Bob WilliamsParticipantHmm, ugly, but good to know. Thanks!
August 23, 2022 at 3:27 PM #47810
Daniel LeuParticipantI use one global variable/object for this purpose that I share among different Prompters.
-
AuthorPosts
You must be logged in to reply to this topic.