Clear catalog variable field with a script

CCZMAX1
Mega Sage

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

 

CCZMAX1_0-1686642382720.png

 

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');       }

}

}

5 REPLIES 5

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.

https://www.servicenow.com/community/developer-articles/getxmlwait-alternative-for-service-portal/ta...

 

This is now working.

Thank you.

Max