Script to Auto-populate email address into field within record producer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 09:46 AM
Hello,
I created a record producer for a service that's designed to allow users to request access to another system on our infrastructure. In the simple workflow, the requestor selects their requested user in the first field that is a "reference" of "user sys_user". I'm wanting to automatically fill in the next field entitled "email" with the email address of the user identified in the previously selected field. Any ideas on how to accomplish this as I don't see much information for this specifically?
See the attached screen shot for better illustration:
- Field 300 - User First & Last Name - Reference > "user sys_user"
- Data captured from "user sys_user" reference in Field 300 automatically populates email of selected user in Field 450.
- Field 450 - user email - Single Line Text (Automatically receives email of previously selected user in Field 300)
Thank you for any information you can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 09:51 AM
You can add onChange client script to populate this value with GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 09:53 AM
Thanks for this, do you have a link to a deeper description of this? I'm interested to learn more about this way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 10:28 AM
You have plenty of resources starting from ServiceNow documentation but here are good starting point posts:
https://www.servicenow.com/community/itsm-articles/on-change-client-side-scripting-scenarios/ta-p/23...
https://www.servicenow.com/community/developer-forum/onchange-client-script-when-a-field-changes/m-p...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 04:42 PM
You can do it directly in the client script if you want. Try this in an onChange client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue != ''){
var user = g_form.getReference('field_300',popEmail);
}
function popEmail(user)
{
g_form.setValue('field_450',user.email);
}
}