Prompter class inside function

Viewing 3 reply threads
  • Author
    Posts
  • August 22, 2022 at 2:06 PM #47801

    Bob Williams
    Participant

    This 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 (passing this.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 Leu
    Participant

    Yeah, 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 Williams
    Participant

    Hmm, ugly, but good to know. Thanks!

    August 23, 2022 at 3:27 PM #47810

    Daniel Leu
    Participant

    I use one global variable/object for this purpose that I share among different Prompters.

Viewing 3 reply threads

You must be logged in to reply to this topic.