- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 04:47 AM
Hi ,
please look at the attachment , the Business Leaders should be auto populated with the Manager of the Business contacts
And if the level of the business contact is a manager then he himself should be populated under Business Leader as well
Kindly help with the Request.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 06:54 AM
Hello,
Please use the below:-
Write a Onchange client script on Business contact field with the below code(Remember to replace the businesscontact and businessleader field name with your fieldname)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getMembers');
ga.addParam('sysparm_name', 'getMembers');
ga.addParam('sysparm_internal_service_name', g_form.getValue('businessconatctfieldname'));
ga.getXML(errorTypeParse);
function errorTypeParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('businessleaderfieldname', answer);
}
}
Then write a script include with name getMembers and have client callable checkbox as true and then use the below code:-
var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMembers: function() {
var arr = [];
var grp_mem = new GlideRecord('sys_user');
grp_mem.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_internal_service_name'));
grp_mem.query();
while (grp_mem.next()) {
gs.log('test');
arr.push(grp_mem.manager.toString());
}
return arr.toString();
},
type: 'getMembers'
});
Please mark my answer as correct based on Impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 04:55 AM
Use the onChange Client script on Business Contact field.
- use condition to check if Business contact is Manager
-- if Use populate the same value as Business Leader
else
-- Populate BuisnessContact.Manager to Business leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 05:20 AM
hello,
Those are list type fields so can there be multiple contacts selected and if yes then do you want to populate managers of all contacts together in the leader field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 05:26 AM
Yes Saurav, there can multiple contacts selected
then have to populate managers of all contacts together in the leader field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 06:54 AM
Hello,
Please use the below:-
Write a Onchange client script on Business contact field with the below code(Remember to replace the businesscontact and businessleader field name with your fieldname)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getMembers');
ga.addParam('sysparm_name', 'getMembers');
ga.addParam('sysparm_internal_service_name', g_form.getValue('businessconatctfieldname'));
ga.getXML(errorTypeParse);
function errorTypeParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('businessleaderfieldname', answer);
}
}
Then write a script include with name getMembers and have client callable checkbox as true and then use the below code:-
var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMembers: function() {
var arr = [];
var grp_mem = new GlideRecord('sys_user');
grp_mem.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_internal_service_name'));
grp_mem.query();
while (grp_mem.next()) {
gs.log('test');
arr.push(grp_mem.manager.toString());
}
return arr.toString();
},
type: 'getMembers'
});
Please mark my answer as correct based on Impact.