Callback function not being executed

Winston
Tera Guru

I'm trying to use the g_modal.showFrame in a UI action to update a record then after being close run a callback function. 

Kb0743790 says "callback Function will be called after modal is closed, with parameters: true if the user confirmed, and false otherwise." but my alert doesn't run after the model is closed out. What am I doing wrong?

https://hi.service-now.com/kb_view.do?sysparm_article=KB0743790

function onClick(g_form) {
	var url = '/sys_user.do?' + 
		'&sysparm_query=sys_id=' + g_form.getValue('caller_id') +
		'&sysparm_view=itil' + 
		'&sysparm_form_only=true';
	g_modal.showFrame({
		url: url,
		title: 'Update User Record',
		size: 'xl'}).then(function() {g_modal.alert('Check.');});
}
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

can you share complete script?

unable to access the HI link

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Copied from the KB page:

Looking at this documentation for g_modal object it should be able to implement a solution by using g_modal.showFrame function inside the workspace specific script:

showFrame({title, url, size, callback})
@param {String} title The title to be displayed
@param {String} url The url to be loaded in the IFrame
@param {Sting} size Size of the modal: 'xs', 'sm', md', 'lg', 'xl', 'fw'
@param {Function} callback Function will be called after modal is closed, with parameters: true if the user confirmed, and false otherwise.
@returns {Promise} Resolved when the IFrame modal is closed

It is necessary to pass any input arguments to the UI Page using query arguments in the constructed URL.

For example, here is workspace client script to display a UI page called mytest passing in an argument called name with the value "richard":

function onClick(g_form) {
g_modal.showFrame({title: 'Richard Test', url: 'mytest.do?name=richard', size:'sm'}).then(function() {});
}

Winston
Tera Guru

The .then(function(){}) works with the g_form.save() method. So it saves the record then throws up the alert message.

function onClick(g_form) {
  g_form.save().then(function(){
    g_modal.alert('Check.');
    });
}

But the alert doesn't run after the model frame is closed out. So for what ever reason it's not registering that the first function is finished running in the below script?

function onClick(g_form) {	
	
	var url = '/sys_user.do?' + 
		'&sysparm_query=sys_id=' + g_form.getValue('caller_id') +
		'&sysparm_view=itil' + 
		'&sysparm_form_only=true';
	
	g_modal.showFrame({
		url: url,
		title: 'Update User Record',
		size: 'xl',
	}).then(function(){
    g_modal.alert('Check.');
    });
}

Since the Kb0743790 says "callback Function will be called after modal is closed, with parameters: true if the user confirmed, and false otherwise."

I think it's not returning true to the callback function because the user isn't confirming anything on the g_modal.showFrame page only updating the user record. So since it's not returning true the call back function isn't running?

find_real_file.png