- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:21 AM
Hi Team,
I have a requirement to get group manager and group type based on reference field which refer group table.
SI is Shown below,
var Get_group_type_nd_manager = Class.create();
Get_group_type_nd_manager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGrouptype: function() {
var group_sys_id = this.getParameter('group_sys_id');
var group_records = new GlideRecord('sys_user_group');
group_records.addQuery('sys_id', group_sys_id);
group_records.query();
if (group_records.next()) {
var manager = group_records.manager;
var group_type_sys_id = this.getParameter('group_tp_sys_id');
var group_type_records = new GlideRecord('sys_user_group_type');
group_type_records.addQuery('sys_id', group_type_sys_id);
group_type_records.query();
if (group_type_records.next()) {
var grptype = group_type_records.name;
if (!manager && grptype == 'itil') {
return '0';
} else if (manager && manager.active == true && grptype == 'security') {
return '1';
} else if (manager && manager.active == false && grptype == 'security') {
return '2';
} else {
return '3';
}
}
}
},
type: 'Get_group_type_nd_manager'
});
client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var modified_group = g_form.getReference('group_to_be_modified', callback);
function callback(modified_group) {
var group_sys_id = g_form.getValue('group_to_be_modified');
var type = modified_group.type;
var email = modified_group.mail;
// g_form.setValue('group_owner', modified_group.manager);
if (!email) {
var ga = new GlideAjax('Get_group_type_nd_manager '); //this is the script include
ga.addParam("sysparm_name", "getGrouptype"); //this is the function within the script include
alert("Inside Call back function");
alert(group_sys_id);
ga.addParam("group_sys_id", group_sys_id);
ga.addParam("group_tp_sys_id", type);
// alert(group_sys_id);
ga.getXML(getResponse);
}
function getResponse(response) {
alert("Inside Response function");
var values = response.responseXML.documentElement.getAttribute('answer').toString();
alert("Inside after Response function");
if (values == '0') {
// alert('manager is empty');
alert('0');
} else if (values == '1') {
alert('1');
} else if (values == '2') {
// alert('manager is Inactive');
alert('2');
} else if (values == '3') {
// alert('manager is Inactive');
alert('3');
}
alert('end of function');
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 06:26 AM
Hello @Akshaya14
You can refer below script . (Tested on my PDI)
On my PDI I got values of manager and type. So you can same script . Just need to add if statement in client script
1) Script Include
var getGroupMangerandType = Class.create();
getGroupMangerandType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
details: function() {
var userObj = {};
// fetch group manager and type
var gr = new GlideRecord('sys_user_group');
if (gr.get(this.getParameter('sysparm_userSelaected'))) {
// for below lines use backend names of 'manager' and 'type' fields
userObj.grManager = gr.manager.getDisplayValue();
userObj.grType = gr.type.getDisplayValue();
}
return JSON.stringify(userObj);
},
type: 'getGroupMangerandType'
});
2) Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//fetch group
var group = g_form.getValue('group_to_be_modified');
// call script include
var userDetails = new GlideAjax('getGroupMangerandType');
userDetails.addParam('sysparm_name', 'details'); // "details" is the function name that present in script include
userDetails.addParam('sysparm_userSelaected', group);
userDetails.getXMLAnswer(function(response) {
var userObj = JSON.parse(response);
// alert("manager :"+userObj.grManager); manager and type of group
// alert("type :"+userObj.grType);
//you can use if condition here by using "userObj.grManager" and "userObj.grType")
});
}
Please mark this as correct answer/accepted and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:34 AM
What is the question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 06:07 AM
I have one reference variable " Group to be modified" refer group table. After selecting the group need to get Group type and manager of that group. Based on group manager active state and type need to perform following operation,
1. if group type is security then need to check group manager active state and give alert .
2. if group type is other than security need to display one another variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 06:26 AM
Hello @Akshaya14
You can refer below script . (Tested on my PDI)
On my PDI I got values of manager and type. So you can same script . Just need to add if statement in client script
1) Script Include
var getGroupMangerandType = Class.create();
getGroupMangerandType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
details: function() {
var userObj = {};
// fetch group manager and type
var gr = new GlideRecord('sys_user_group');
if (gr.get(this.getParameter('sysparm_userSelaected'))) {
// for below lines use backend names of 'manager' and 'type' fields
userObj.grManager = gr.manager.getDisplayValue();
userObj.grType = gr.type.getDisplayValue();
}
return JSON.stringify(userObj);
},
type: 'getGroupMangerandType'
});
2) Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//fetch group
var group = g_form.getValue('group_to_be_modified');
// call script include
var userDetails = new GlideAjax('getGroupMangerandType');
userDetails.addParam('sysparm_name', 'details'); // "details" is the function name that present in script include
userDetails.addParam('sysparm_userSelaected', group);
userDetails.getXMLAnswer(function(response) {
var userObj = JSON.parse(response);
// alert("manager :"+userObj.grManager); manager and type of group
// alert("type :"+userObj.grType);
//you can use if condition here by using "userObj.grManager" and "userObj.grType")
});
}
Please mark this as correct answer/accepted and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 09:42 PM
Is that my script find helpful for you?