How to autopopulate name of logged in user in field on a form?

Aditya Sinha
Tera Contributor

I have a form where a field needs to be populated with name of logged in user.  I am using an on load script however it is not working, (I have checked the UI type to ALL).

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   var gq=new GlideRecord("sys_user");
   //alert((g_form.getReference(g_user.userID)));
   var ab=g_user.userID;
   
   gq.addQuery("user_name",ab);
   gq.query();
   

   g_form.setValue("field name",gq.name);

   
}
11 REPLIES 11

Hey Sandeep. Can there be a reason for the filed still not getting populated apart from this?

I have copied the field name correctly, however my g_form.setValue("field name",val) command isn't populating my field. I have taken care of the UI and checked it to ALL. Any suggestions are welcome

SANDEEP28
Mega Sage

@Aditya Sinha Share screenshot of your client script