Make catalog variables editable for a particular group memebers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I have a requirement to make the RITM variables editable for a particular group members once the RITM is in 1st stage of approval.
for example: 1st stage of approval goes to 'Business Solution' group, so the members of that group should have access to edit the variables on the RITM form.
I have written a client callable script include to check the group membership. If it return true, variables should be editable over RITM form but the variables are not editable.
Script Include:
var canEditRITMVariables = Class.create();
canEditRITMVariables.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// Client-callable function
canEditRITMVariables: function() {
var userSysId = this.getParameter('sysparm_user');
var groupSysId = this.getParameter('sysparm_group');
if (this.isUserInGroup(userSysId, groupSysId)) {
return 'true'; // user can edit
}
return 'false'; // restrict editing
},
// Helper: check group membership
isUserInGroup: function(userSysId, groupSysId) {
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('user', userSysId);
grMember.addQuery('group', groupSysId);
grMember.query();
return grMember.hasNext();
},
type: 'canEditRITMVariables'
});
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue("cat_item") == "d025b6ff870ce950fa770d47cebb3566") {
var ga = new GlideAjax('canEditRITMVariables');
ga.addParam('sysparm_name', 'canEditRITMVariables');
ga.addParam('sysparm_user', g_user.userID);
ga.addParam('sysparm_group', '56f1f8240f9d82004fb50f8ce1050e2f'); // replace with group sys_id 56f1f8240f9d82004fb50f8ce1050e2f
ga.getXMLAnswer(function(response) {
var canEdit = response === 'true';
if (!canEdit) {
g_form.setVariablesReadOnly(false);
}
});
}
}
Can someone plz help on this why this code is not working. I have ran the code in the scripts-background and the result is coming as true still the variables are non-editable for the users.
Thansk,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @roomawakar,
just on the very first sight, you can try to remove the quotes in Script include returns:
return true; //not 'true'
return false; //not 'false'
And let me know if that helped
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can do it using display BR and scratchpad:
or:
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Solution didn't work.
Thanks,
Rooma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
g_form.getValue("cat_item") == "d025b6ff870ce950fa770d47cebb3566" , you have used this, does this mean you have written the client script on RITM table? or it is a catalog client script?
In case this is a client script on RITM table, use the below to make variables readonly true and false:
g_form.setReadOnly('variables.<variableName>', true);