- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 06:32 PM - edited 12-04-2023 06:40 PM
Hi All,
We have one variable "type" and have many choices , as of now we display based on , if "opened by is same as Manager" then we display all the choices , but we need to add one more condition that if the person belongs to the one of these groups(Business or Advisors) , then he also able to see those choices for that field
Please help me to achieve this
Client script
Thanks
Ramu
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 04:39 AM
@Ramu6 Update the client callable script include with the following script and check, if still it didn't work. Check the system log that starts MAK and share it here. If possible share your client script and script include screen shots.
var CustomUserUtilsClient = Class.create();
CustomUserUtilsClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkManagerOrGroupMem: function(){
var subject = this.getParameter("sysparm_subject");
var opened_by = this.getParameter("sysparm_opened");
var usrGr = new GlideRecord("sys_user");
gs.info("MAK: opened: " + opened_by + " Subject: " + subject);
if(usrGr.get("sys_id", subject)){
var manager = usrGr.getValue('manager') + '';
gs.info("MAK: opened: " + opened_by + " Manager: " + manager);
if ( manager == opened_by){
return 'true';
}
}
var grpGr = new GlideRecord("sys_user_grmember");
grpGr.addEncodedQuery("group.name=Business^ORgroup.name=Advisors^user=" + opened_by);
grpGr.query();
if(grpGr._next()){
return 'true';
}
return 'false';
},
type: 'CustomUserUtilsClient'
});
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 07:58 AM
Hi @Ramu6
Unfortunately I don't see any other way to check the user group membership from client script.
Few may say using GlideRecord in client script, but personally I don't prefer and is not a good practice.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 03:44 AM - edited 12-06-2023 03:51 AM
I have created Script include and made changes to client script , but its only working for group members, but its not working for my first condition that if opened_by is subject person's manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 04:39 AM
@Ramu6 Update the client callable script include with the following script and check, if still it didn't work. Check the system log that starts MAK and share it here. If possible share your client script and script include screen shots.
var CustomUserUtilsClient = Class.create();
CustomUserUtilsClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkManagerOrGroupMem: function(){
var subject = this.getParameter("sysparm_subject");
var opened_by = this.getParameter("sysparm_opened");
var usrGr = new GlideRecord("sys_user");
gs.info("MAK: opened: " + opened_by + " Subject: " + subject);
if(usrGr.get("sys_id", subject)){
var manager = usrGr.getValue('manager') + '';
gs.info("MAK: opened: " + opened_by + " Manager: " + manager);
if ( manager == opened_by){
return 'true';
}
}
var grpGr = new GlideRecord("sys_user_grmember");
grpGr.addEncodedQuery("group.name=Business^ORgroup.name=Advisors^user=" + opened_by);
grpGr.query();
if(grpGr._next()){
return 'true';
}
return 'false';
},
type: 'CustomUserUtilsClient'
});
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 04:56 AM
Thanks for the code, i have tried with , the results are like below
I think it was entering into the if condition
if(usrGr.get("sys_id", subject)){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:37 AM
@Ramu6 The script include is not receiving the subject sys_id. Please try this client script and see whether you are getting the sys_id or not in alert.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var opened_by = g_form.getValue("opened_by");
var user = g_form.getValue("subject_person");
alert(user);
if (newValue != '') {
var ga = new GlideAjax("CustomUserUtilsClient");
ga.addParam("sysparm_name", "checkManagerOrGroupMem");
ga.addParam("sysparm_subject", user);
ga.addParam("sysparm_opened", opened_by);
ga.getXMLAnswer(processResponse);
}
function processResponse(answer){
if(answer == 'true'){
g_form.addOption("u_type_of_leave", "Garden Leave", "Garden Leave");
//Add code for remaining options
}else{
//Show the options if the opened by person is not manager and not member of groups
g_form.removeOption("u_type_of_leave", "Garden Leave", "Garden Leave");
//Add code for remaining options
}
}
}
Anvesh