How can I set a default value of the requesters company on a record producer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 01:27 AM
Hi,
I am hoping I can get some help here.
I have created a Company variable on a record producer with a reference field type.
How can I set a default value in the company field (variable) to show the requesters company? on the variable within employee centre.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 08:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 05:28 AM
This is what we ended up using.
javascript: var company; var rec = new GlideRecord('sys_user'); rec.get(gs.getUserID()); company = rec.company; company;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 05:28 AM
Thank you for your reply and help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2022 08:55 AM
Hi Daniel,
Not a default value per se, but it will look the same. This example assumes you have a reference variable for requestor (named v_requestor). The advantage to having the Requestor variable is it gives you the ability to allow someone to submit on behalf of someone else. Then you can also have a similar script onChange of Requestor, so that Company is updated when the Requestor changes. If you want to create the requestor variable, you can have it default to the current user by putting javascript: gs.getUserID() in the Default value field, and map it to Contact or whatever. Next create an onLoad Catalog Client Script that will populate the Company variable (named v_company in this example) based on the company of the requestor variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = g_form.getReference('v_requestor', userLookup);
function userLookup(user) {
g_form.setValue('v_company', usr.company);
}
}
If you don't want a Requestor variable, your onLoad script would need to call a Script Include via GlideAjax, passing in the current user for the SI to return the Company. Not necessarily more difficult, just more lines of code and another script.