- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 11:59 AM
Hi All -
I am looking for the best way to create/populate a custom field on the User form that I will name MGR Email, and it would do the following:
- prefix with a static value of: mgr
- then grab the value in the Location field for that user (Location on sys_user)
- then suffix it with the email domain: @xyz.com
So if I had a user record open and that user's location value was 123, then this MGR Email field would be populated for that user as: mgr123@xyz.com
If the user's location was empty - then it should result in no value populated within this MGR Email field for that user.
Thank you!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 01:35 PM
Did you try this ?
This should be a before business rule with insert and update check boxes checked. Below is the script.
if (current.location!='')
current.your_mgr_email_field = 'mgr'+current.location.name+'@xyz.com';
else
current.your_mgr_email_field = '';
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 08:06 AM
Hello - Thank you for this. I have tried it out and I can't get it to populate the data into the field. This is what I have:
String field on user form:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getUserLocEmailID');
ga.addParam('sysparm_name','getdetails');
ga.addParam('sysparm_caller', newValue);
ga.getXML(AsyncCall);
}
function AsyncCall(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer != ''){
var msgemail = 'mgr' + answer + '@XXXXXX.com';
g_form.setValue('u_mgr_email', msgemail);
}
else
g_form.setValue('u_mgr_email', '');
}
Script Include:
var getUserLocEmailID = Class.create();
getUserLocEmailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdetails: function(){
var gr = new GlideRecord('sys_user');
if(gr.get(this.getParameter('sysparm_caller')))
{
if(gr.getValue('location') != '')
return gr.getDisplayValue('location');
}
},
type: 'getUserLocEmailID'
});
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2017 10:19 PM
Please have the onChange() client script on user's field for which you want to populate the data as per the user's location instead of MGR Email ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 06:36 AM
Hello - apologies for the delayed reply. I don't quite understand what you are referring to. I would like for this new MGR Email field to always be populated in the User record, as long as the user location field is not empty. I will be using this field to generate email notifications. So for all the existing users and then all the users that are populated each day, this field should just be automatically populated if the user has a location.
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 01:35 PM
Did you try this ?
This should be a before business rule with insert and update check boxes checked. Below is the script.
if (current.location!='')
current.your_mgr_email_field = 'mgr'+current.location.name+'@xyz.com';
else
current.your_mgr_email_field = '';
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 02:17 PM
Hi Sanjiv -
Thanks for your response. The business rule is not working for me. Please see screenshots:
(function executeRule(current, previous /*null when async*/) {
if (current.location !='')
current.u_mgr_email = 'mgr'+current.location.name+'@abcsupply.com';
else
current.u_mgr_email = 'blank';
})(current, previous);