Populate users department when submitting on behalf of another user

Terry Carter Jr
Tera Contributor

I was wondering if anyone has had any luck in populating a user's department from the user table and also allow for that department to be updated if the Requested For field is changed to another user if submitting on behalf of another employee?

I have it working by using the default value from the variable field I created that will reference the department using code I found from previous discussions on the community but I want it to work the same way if you put in a request on behalf of another user.   Right now it only pulls my info and if I place another user in the Requested For field it keeps my department without updating to that users department.  

This is what I have in the default value as of right now of my custom variable:

javascript:gs.getUser().getRecord().getValue("department");

javascript:gs.getUser().getRecord().getDisplayValue("department");

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

ok, then have your GlideAjax in your onChange client script pass the value from the Requested For field...then have your script include do a GlideRecord query so the sys_user table to lookup the department field for that user to pass back to the client script.   let me know if you need help with the script


View solution in original post

9 REPLIES 9

patricklatella
Mega Sage

Yep Terry, like Prateek is suggesting...use   GlideAjax in an onChange client script with a script include to achieve this.   Is the user's "Department" field populated on the sys_user table for all your user's?


Yes it is located on the user table and populated when the user is added to the system from LDAP.


patricklatella
Mega Sage

ok, then have your GlideAjax in your onChange client script pass the value from the Requested For field...then have your script include do a GlideRecord query so the sys_user table to lookup the department field for that user to pass back to the client script.   let me know if you need help with the script


Thank you Patrick!   I will reach out to you if I need assistance with the script.  


patricklatella
Mega Sage

excellent Terry, glad to help!