- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 10:46 AM
Hello,
I have an onSubmit Catalog Client script which calls the script include. The script include returns 2 values response and error code. I want to set these 2 values in the variables
onSubmit Catalog Client script:
function onSubmit() {
var Nasa = new GlideAjax("NASA_Utils");
Nasa.addParam('sysparm_name', 'generatePassword');
Nasa.addParam('sysparm_accountID', app[0]);
Nasa.addParam('sysparm_userID', app[1]);
// alert('>' + app[0] + '<>' + app[1]);
Nasa.getXMLAnswer(setValue);
}
function setValue(response) {
var answer = JSON.parse(response);
// alert works, I can see values in alert for these 2 values
g_form.setValue('response', answer.resp);
g_form.setValue('error_code_and_message', answer.error_code_and_message);
}
Part of Script include
var answerObj = {};
answerObj.newPass = newPass;
answerObj.resp = resp;
answerObj.error_code_and_message = error_code_and_message;
return JSON.stringify(answerObj);
If i add a alert statement i see the values come from the SI, and even see it set on the catalog form response and error_code_and_message variables, however these variables are blank in RITM
Catalog Item screen shot after I click submit ( I can see Response and Error code been set):
RITM screen shot:
Thanks,
Suraj
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 10:51 AM
Hi,
Most likely this is because you're calling a script include in an onSubmit client script which is usually never a good idea and leads to issues that are similar to this.
Are you able to address this through another method, such as in the catalog item workflow? Or in a Business Rule, instead? Or even in an onChange client script.
For testing, you can change this to an onChange client script, just to test and see and you'll most likely see that it works, it'll set the values on catalog form, submit, and see it populated on the RITM variable, etc.
What's happening here is that you're submitting the form at the same time this SI is retrieving information, by the time it comes back, the form has already saved and moved on.
SI are async, onSubmits are not, so it's not timing up.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 10:51 AM
Hi,
Most likely this is because you're calling a script include in an onSubmit client script which is usually never a good idea and leads to issues that are similar to this.
Are you able to address this through another method, such as in the catalog item workflow? Or in a Business Rule, instead? Or even in an onChange client script.
For testing, you can change this to an onChange client script, just to test and see and you'll most likely see that it works, it'll set the values on catalog form, submit, and see it populated on the RITM variable, etc.
What's happening here is that you're submitting the form at the same time this SI is retrieving information, by the time it comes back, the form has already saved and moved on.
SI are async, onSubmits are not, so it's not timing up.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 10:54 AM
Allen, thanks for the response
yes other method works, I already tried them (thru workflow) but i wanted it to setvalues onSubmit.
I guess i will have to change it back.
Thanks for your help !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 11:02 AM
Hi,
Indeed.
If my reply above helped answer your question and guide you correctly, please mark as Correct, if you don't mind.
Take care!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!