Script Include and catalogue client script not checking the correct referenced field

matthew_hughes
Kilo Sage

I'm running a catalogue client script and a script include to the value selected in a field called "new_business_division" on a catalogue item. The purpose of both scripts is to prevent a user submitting a request if the selected value in the "new_business_division" field doesn't match the requirements set out in the script include. 

 

I've attached a copy of the script include and catgalogue client script to this quesiton.

 

When I click 'Submit' the following message occurs:

{"type":"xml","responseText":"<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml sysparm_max=\"15\" sysparm_name=\"checkBusinessUnitType\" sysparm_processor=\"LBGBusinessUnitFunctionCheck\"/>","responseXML":{"location":null}}

 

I'm not sure why because my script include and catalogue client script don't refer to the location table.

 

Script Include:

var LBGBusinessUnitFunctionCheck = Class.create();

LBGBusinessUnitFunctionCheck.prototye = Object.extendsObject(AbstractAjaxProcessor, {

    checkBusinessUnitype: function() {

 return 'Hello world';

  var selectedBUF = this.getParametr('sysparm_business_unit_function');

  var businssUnitFunction = new GlideRecord('cmn_department'); businssUnitFunction.addEncodedQuery('u_active=true^u_department_type=Business Unit^ORu_department_type=Function');

  

  businssUnitFunction.addQuery('sys_id',selectedBUF);

  

  businssUnitFunction.query();

  if(businssUnitFunction.next()) {

   //Submission will succeed

   return 'ok';

  }else {

   return "This Department is not valid";  }

  

    },

 type: 'LBGBusinessUnitFunctionCheck'

});

   

Catalogue Client Script:

 

function onSubmit() {

 // If we already valided, continue

 if (g_scratchpad.isFormValid) {

  g_scratchpad.isFormValid= false;

  return true;

 }

 /f we didn't, get the action and do the check

 var callAJAXOnSubmitValidtion = function(response) {

  alert(JSON.stringify(response));

  // Get the answer from the XML response

  var answer = response.responseXML.documentElement.getAttibute("answer");

  // If the answer was "ok" then we ca submit

  if (answer == "ok") {

   g_scratchpad.isFormValid = true;

   g_form.submit("bmit");

  }

  else {

   // If it wasn't, display an error popup

   alert(answer);   

  }

 };

 // Call GlideAjax to get the relationships

 vaax = new GlideAjax("LBGBusinessUnitFunctionCheck");

 ajax.addParam("sysarm_name","checkBusinessUnitType");

 ajax.addParam("sysparm_business_unit_function",g_form.getValue("new_business_division"));

 ajax.getXML(callAJAXOnSubmitValidation); 

 // Stop the submit

 return false;

}

1 REPLY 1

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @matthew_hughes ,

 

Please make your in the format as specified in below article.  As the in Portal getXMLWait not works correctly so we will have to stop the client script untill we get the response from script include. So please check below article and look into the solution part. Try that and let me know further.

getXMLwait alternative for Service Portal 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy