- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 04:00 PM
Hello Everyone,
I am looking to populate a reference field (manager) based on a string field (manager_email) on sys_user table. The string field has the user's email address. In order to ensure the manager field has the correct user name, we would like to reference the email to auto populate the manager name. Please advise with a script if possible
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:29 AM
I used a "before" business rule "insert/update" and this worked. Script below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 12:05 AM
Hi @WP1 ,
You can refer the below link,
https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side
This has different methods and also detailed explanation of which one could be the most efficient one. You can easily build your script that you are looking for.
If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:19 AM
Hi WP1,
Client script: (change the Table and Field name values below to your table.)
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (oldValue == newValue) {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('GetUserManager');
ga.addParam('sysparm_name', 'getAssignedToManager');
ga.addParam('sysparm_manager_email', g_form.getValue("manager_email"));
ga.getXMLAnswer(getResponse);
// callback function for returning the result from the script include
function getResponse(response) {
var man = response;
alert('Manager: ' + man);
g_form.setValue('u_manager', man); // manager reference field name
}
}
Check the manager reference field name, I have 'u_manager' above. Script include:
Updated script for your use case:
var GetUserManager = Class.create();
GetUserManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignedToManager: function() {
var userEmail = this.getParameter("sysparm_manager_email");
var user = new GlideRecord('sys_user');
user.addQuery('email', userEmail);
user.query();
// gs.info("GetUserManager: Found " + user.getRowCount() + " user records.");
if (user.next()) {
result = user.manager.getValue();
// gs.info('GetUserManager: user manager = '+ result);
}
else {
result = "Unknown";
}
// gs.info("GetUserManager: Returning string: " + result);
return result;
},
type: 'XUserDetailsAjax'
});
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:29 AM
I used a "before" business rule "insert/update" and this worked. Script below