Clear catalog variable field with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 12:48 AM
Hi, I have a multi row variable set with a onChange Catalog client script that runs for a field in the variable set.
The script works if the user clicks in another field on the form or anywhere on the form before pressing the Add button. If they press the Add button first the row it added before the script is fully executed to clear the new ‘New Service’ field if the script returns true. The message appears but the field is not cleared because the row has already been added.
I tried using onSubmit but that displays the error message but does not clear the field when the return is true.
Does anyone know how I could overcome this. This is the code I have so far that calls a script includes.
Many thannks
Max
function onChange()
{
var new_service = g_form.getValue('new_service');
var ga = new GlideAjax ('service_and_offerings');
ga.addParam('sysparm_name', 'check_service_name');
ga.addParam('sysparm_new_service', new_service);
ga.getXMLAnswer(callbackFunction);
function callbackFunction(serviceExists)
{
serviceExists = Boolean(serviceExists);
if(serviceExists === true)
{
g_form.clearValue('new_service');
alert('This service name cannot be created as it already exists'); }
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 06:39 PM
Thanks Brad, for pointing me in the right direction. When I used the getXMLWait I got the following JavaScript error in the browser:
'GlideAjax.getXMLWait is no longer supported',
In my search for a solution I found the following workaround.
This is now working.
Thank you.
Max