how to prepopulate a variable value onload

abcmh
Giga Contributor

I have a variable on my item , the value of which i am trying to prepopulate onload of the item.

This variable is a single line text & i have given the default value as javascript:gs.getUser().getRecord().getValue('u_business_unit_id');

I basically want to populate the variable with a default value of the business unit id from the user record on load of the item.

Its not working and not returning the value.

Any suggestions?

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Hi Amol,



Use the following



javascript:  


var gr = new GlideRecord('sys_user');  


gr.addQuery('sys_id',gs.getUserID());  


gr.query();  


if(gr.next()){  


  gr.u_business_unit_id;  


}



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

8 REPLIES 8

SanjivMeher
Kilo Patron
Kilo Patron

Hi Amol,



Use the following



javascript:  


var gr = new GlideRecord('sys_user');  


gr.addQuery('sys_id',gs.getUserID());  


gr.query();  


if(gr.next()){  


  gr.u_business_unit_id;  


}



Please mark this response as correct or helpful if it assisted you with your question.

Should this script be added to the Default value of the variable or in client script onload event?


To the default value.



Please mark this response as correct or helpful if it assisted you with your question.

Something like this



find_real_file.png



Please mark this response as correct or helpful if it assisted you with your question.