setValue on reference field

DreDay3000
Giga Guru

Hello, I have a reference field that I want to set onLoad. I have a client script that works on the backend form but does not work in workspace. In workspace the field shows "(Empty)". Is there a way to set the value on the reference field in configurable workspace? I have tried setDisplayValue but that did not populate the field

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   g_form.setValue('region','UNITED STATES');
   g_form.setValue('site','CALIFORNIA');
   g_form.setValue('campus','SACRAMENTO');
}
1 ACCEPTED SOLUTION

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @DreDay3000 ,

 

You cannot set the value of a reference field using g_form.setValue('region','UNITED STATES'); rather you need to pass the sys_id of the 'united state' record in the value. 

 

Eg> g_form.setValue('region','sys_id'); //in place of sys_id, open the united state record from the table and copy the sys_id by right clicking on the form header > copy sys_id (this will be a 16 digit hexadecimal number)

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

2 REPLIES 2

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @DreDay3000 ,

 

You cannot set the value of a reference field using g_form.setValue('region','UNITED STATES'); rather you need to pass the sys_id of the 'united state' record in the value. 

 

Eg> g_form.setValue('region','sys_id'); //in place of sys_id, open the united state record from the table and copy the sys_id by right clicking on the form header > copy sys_id (this will be a 16 digit hexadecimal number)

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

KevinBellardine
Kilo Sage

You can use setDisplayValue, just be sure that the value you're passing is unique in the target table