Display business rule is not working

Sujata Lenka
Tera Contributor

I want to fetch Location data to my incident form, by using display business rule and onchange client script but this is not working. please help .

 

Display BR:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    g_scratchpad.location = current.caller_id.location.name;

})(current, previous);

On change Client script:
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var location = g_scratchpad.location;
g_form.setValue('u_callers_location', location);

   
}
 
 
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Sujata Lenka 

business rule script is correct, but your onChange will only work when the field changes.

I believe you want an onload client script to set the location so use onLoad and this line of code

function onLoad(){

   var location = g_scratchpad.location;
g_form.setValue('u_callers_location', location);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader