Show values in a list collector variable in a confirm window whenever you submitt a catalog item

Sri Harsha2
Tera Expert

Hello Everyone,

 

Please suggest me how to show value in a list collector variable into a confirm window whenever you submit a catalog item , I am using  " confirm('Do you want to continue with for ' + array + '?'); " in the onSubmit client script, i am getting sysIDs, need to  show display value.

Thank you.....

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You'll need your onSubmit script to call a GlideAjax with the variable value.  The Script Include will query the referenced table and return a list of the display values.  So something like this if we're talking about a list collector on the sys_user table.  If you're using Service Portal, you'll need to do something else as the submit will complete before the response is received from the server, so the confirmation will appear after the request has been created.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var ga = new GlideAjax('UserUtils'); //name of Script Include
    ga.addParam('sysparm_name', 'getUsers'); //name of function 
    ga.addParam('sysparm_user', g_form.getValue('v_users'); //list collector variable name
    ga.getXMLAnswer(function(answer){
        confirm('Do you want to continue for ' + answer + '?');
    });
}

Script Include with Client callable box checked
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
	getUsers: function() {
            var answerArr = [];
            var users = this.getParameter('sysparm_user');
            var gr = new GlideRecord('sys_user');
            gr.addQuery('sys_id', 'IN', users);
            gr.query();
            while (gr.next()) {
                answerArr.push(gr.name);
            }
            return answerArr.join(', ');
        },
    type: 'UserUtils'
});

Ankur Bawiskar
Tera Patron
Tera Patron

@Sri Harsha2 

you need to use GlideAjax here which is synchronous. What's the requirement here to show the confirm box with the same values again to user?

Remember synchronous GlideAjax doesn't work directly in portal

Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit

How To: Async GlideAjax in an onSubmit script

Asynchronous onSubmit Catalog/Client Scripts in ServiceNow

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thank  You