
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2023 09:06 AM
I have a catalog item where, at the catalog task level, the technician is required to select a record. If the record doesn't exist, they are required to provide the details for a new record, check a checkbox variable, then save the task. Doing so triggers the below onSubmit client script that calls a script include that creates the record. The script include returns the sys_id of the new record, and the client script is supposed to set an existing variable to that value. However, that last part (in red) isn't working.
I have confirmed that the script include is working as expected and returning the correct sys_id.
Here is the client script. What do I need to do differently to get it set and store the variable's new value?
function onSubmit() {
//Type appropriate comment here, and begin script below
var newFP = g_form.getValue('vs_create_new_faceplate');
var fp = g_form.getValue('vs_select_faceplate');
if (newFP == 'true' && fp == '') {
var ga = new GlideAjax('FaceplateJackAjax');
ga.addParam('sysparm_name','createFaceplate');
ga.addParam('sysparm_fpname',g_form.getValue('vs_new_faceplate'));
ga.addParam('sysparm_room',g_form.getValue('vs_select_room'));
ga.addParam('sysparm_numjacks',g_form.getValue('vs_number_of_jacks'));
ga.getXML(serverResponse);
}
function serverResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer); //<-- script include creates the record and returns the correct sys_id
g_form.setValue('vs_select_faceplate',answer.toString()); //<-- this is not working
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 04:37 AM
I ended up setting the variable in the script include rather than the client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2023 12:15 PM
I don't think this would be preventing it from working, but you don't need toString() here since the server can only return a string value, so var answer is already a string. So your alert on answer shows the expected sys_id? What is the variable type of vs_select_faceplate? If it is a reference to the table on which the Script Include just created a new record, I could see how the reference variable would not contain that new record. Since this is being done onSubmit, I would do this as a Run Script on your Workflow after this Catalog Task activity if they are closing the task after checking the box, or if they are just saving the record you should be able to do it as a Business Rule on the sc_task table instead. Running it all on the server will set the value of the variable, assuming the sys_id is valid for the referenced table, without the UI constraints of a reference qualifier or in this case the record not existing when the form is loaded. You can run the BR before update, with conditions in the script so that it doesn't run on every Catalog Task update. Even if they are just saving the Catalog Task, you shouldn't need to refresh/reload (again) after saving to see the variable populated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2023 01:37 PM
Thank you, Brad. Yes, it's a reference variable to the table where the script include just created a record. I tried to do it first as a business rule, but it wasn't being triggered - I presumed that was because the catalog task isn't 'updating' on save because the only thing that changed was a variable, and I think a variable change only counts as an update at the RITM level. But I can't do it at the RITM level because it only applies to certain catalog tasks.
The toString() was just a last ditch attempt to make it work. I tried it without that as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 04:37 AM
I ended up setting the variable in the script include rather than the client script.