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

Yep, that's what i did . Added it to the default value & it is working fine now. Thanks for your help.


Also , will i be able to get a handle to this variable if i keep it hidden by unchecking the visible checkboxes in the Availability section.


I only need the value of it in an email at the end of the workflow process.


Yes. You can keep it hidden on the form using UI policy or onLoad Client Script. But dont remove it from the form.



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

Thanks for the input.   I used an onload catalog client script to hide the variable. I am able to get a handle to it in a mail script to populate the value of the variable in the email.