Fetch manager name from assignment group and show as field message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2024 09:10 PM
Hi Everyone,
Result ---Undefined
please assist me on this asap
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:53 AM
Assignment group name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:57 AM
hi @Jyoti Ranjan Se ,
Then Assignment group field is not reference field?.
if not then above script wont work because above script only work for reference it will take sysid and search for that record in group table so if your script want to work for string field make changes in code
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManger: function() {
var userId = this.getParameter('sysparm_sys_id'); // Get the Sys ID from the client script
var result = {};
if (userId) {
var userGR = new GlideRecord('sys_user_group'); // Query the sys_user_group table
userGR.addQuery('name',userId);
userGR.query();
if(userGR.next()){
gs.log("getManger"+userGR.manager)
result.manager = userGR.manager.getDisplayValue();
}
}
return JSON.stringify(result);
},
type: 'GetUserDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 04:11 AM
i wrote this script .it only gives sysid of manager i want to display manager name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 04:18 AM
Hi @Jyoti Ranjan Se ,
as your script returning sysid because of
var ManagerName =fetchmanager.manager;
if you you do var ManagerName =fetchmanager.manager.name; it will return undefined because of my knowledge we can go upto one level of dotwalking in getReference() method
try this way
client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetUserDetails'); // script include name
ga.addParam('sysparm_name', 'getManger'); // funcation name in script include
ga.addParam('sysparm_sys_id', newValue);
ga.getXMLAnswer(function(response) {
var userDetails = JSON.parse(response);
g_form.showFieldMsg('assignment_group', 'Change Manager: ' + userDetails.manager, 'info');
});
}
Script include:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManger: function() {
var userId = this.getParameter('sysparm_sys_id'); // Get the Sys ID from the client script
var result = {};
if (userId) {
var userGR = new GlideRecord('sys_user_group'); // Query the sys_user_group table
userGR.addQuery('sys_id',userId);
userGR.query();
if(userGR.next()){
gs.log("getManger"+userGR.manager)
result.manager = userGR.manager.getDisplayValue();
}
}
return JSON.stringify(result);
},
type: 'GetUserDetails'
});
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thanks,
BK