- 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-04-2023 08:35 PM
Try to add this OR condition -----
var userGroups = g_user.get('groups');
var isBusinessOrAdvisor = userGroups.indexOf('business') !== -1 || userGroups.indexOf('advisor') !== -1;
if(isBusinessOrAdvisor) {
// your options and choices you wants to show
}
I hope it will help you if yes please mark it accept as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 03:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:01 PM
Hi @Ramu6
You can create a Client Callable Script Include and call that in your Catalog Client Script like as shown below.
Client Callable Script Include:
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");
if(usrGr.get("sys_id", subject)){
var manager = usrGr.getValue('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'
});
Catalog Client Script:
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");
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
}
}
}
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 03:02 AM
Thanks for the response
As i mentioned that we already created one client script for this , so do we way that we can add any script in existing client script without using of script include