Can you help me for write script

IshwarR07
Tera Contributor

Requirements - create entity field in hardware table choices: asia,  europe. create 2 location and based on those two locations if location A is selected then entity should automatically populated as Asia and if location is B then entity should populate as Europe. Whenever new record create or update or insert through transfer map

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var lName = g_form.getDisplayValue('location');
if(lName == 'A'){
    g_form.setValue('u_entity','Asia');
}else if(lName == 'B'){
    g_form.setValue('u_entity','Europe');
}else{
    g_form.clearValue('u_entity');
}
   
these script is not working instead of these what can i write.
3 REPLIES 3

Mark Manders
Mega Patron

Add the entity to the location record and use the dotwalked field from the location table on your target record.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@IshwarR07 

that's not how you get display value of reference field.

update as this, ensure you use correct choice value to set the entity and don't use choice label

 function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue === '') {
         return;
     }
     var lName = g_form.getDisplayBox('location').value;
     if (lName == 'A') {
         g_form.setValue('u_entity', 'Asia');
     } else if (lName == 'B') {
         g_form.setValue('u_entity', 'Europe');
     } else {
         g_form.clearValue('u_entity');
     }

 }

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

@IshwarR07 

Hope you are doing good.

Did my reply answer your question?

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