Client script not working to auto populate the requestor field on form load

NayeemSk
Tera Contributor

I had created a client script to Populate requested name as soon as form loaded with the value from current user. But when I go ahead to load a new form, it stills hows empty. Attached code screenshot.

 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You could do this with one line:

g_form.setValue('requestor_name', g_user.userID);

but note that the field/variable name 'requestor_name' must be exactly correct (case-sensitive) and since g_user.userID returns a sys_id, this field/variable must be a reference type to the sys_user table.

 

SarabpreetS
Tera Contributor

Exactly, adding to what @Brad Bowman  said, that’s usually the main issue.
Most of the time when a field doesn’t populate on form load, it’s either a case-sensitive field name or a type mismatch. Since g_user.userID returns a sys_id, requestor_name needs to be a reference field pointing to the sys_user table.

Also, make sure the script is set as onLoad, is active, and is running on the correct form type (regular form vs. catalog item). With all that in place, the one-line approach you mentioned should work perfectly.

 

If you found this useful, please mark it as Helpful and Accepted.
Sarabpreet Singh