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 Raghav,
Client script is on RITM table but there are around 45 variables which has to be made ReadOnly. It is not feasible to make every variable read only one by one.
Thanks,
Rooma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
In that case you need to get all field in youyr client script as below:
var rwVars = g_form.getEditableFields();
for (var i=0; i<rwVars.length;i++) {
g_form.setReadOnly('variables.' + rwVars[i], false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@roomawakar did you try this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what debugging did you do?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what debugging did you do and what's your findings?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader