onChange Catalog Client Script setting Location # Field

Julia Howells
Giga Guru

I need to have an onChange client script on a catalog item populate another field.

The field 'Site Name' should populate 'Site Number' when Site Name is filled in. Site Name is a reference field to the cmn_location table, and on that table, there is a u_location_number field. This field is what would populate the Site Number field on the catalog item.

I am pretty sure I am missing a step in the script, but not sure where I should fix it. 

find_real_file.png

 

1 ACCEPTED SOLUTION

Musab Rasheed
Tera Sage
Tera Sage

Hello,

The way you are dot walking will not work, so either you have to use Glidereference or Glideajax, here is sample script for glidereference. Also change UI type to 'ALL'

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var gr = g_form.getReference('site_number_name', getData);

if(gr != '')

function getData(gr) 
{ 

           
 
            g_form.setValue('sit',gr.sit_location);

}
       
   
}

Also, try to follow no code approach as well

https://community.servicenow.com/community?id=community_article&sys_id=49deac8ddb92a010ab0202d5ca961967

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

5 REPLIES 5

Musab Rasheed
Tera Sage
Tera Sage

Hello,

The way you are dot walking will not work, so either you have to use Glidereference or Glideajax, here is sample script for glidereference. Also change UI type to 'ALL'

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var gr = g_form.getReference('site_number_name', getData);

if(gr != '')

function getData(gr) 
{ 

           
 
            g_form.setValue('sit',gr.sit_location);

}
       
   
}

Also, try to follow no code approach as well

https://community.servicenow.com/community?id=community_article&sys_id=49deac8ddb92a010ab0202d5ca961967

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab,

I don't see it populating with the data lookup definitions... Am I missing a step?

find_real_file.png

find_real_file.png

See Catalog matcher variable definition is wrong, Matcher table field should be Sys id and in next tab Catalog Setter Variable Definition write reference for number , see screenshot of that article again and do it.

find_real_file.png

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hello,

If you are fine with my reply, Please mark my answer as correct and close the thread.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab