Make a catalog variable editable based on script condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 03:43 AM
in catalog item , i want to make a variable be editable after submitting the request ( on requested item ) if the user is a member of specific group group
i make a catlog client script to evaulate the condition and if the condition is true i use this statement
g_form.setReadOnly("variable_name",false);
but nothing changes , I'm asking is this method available in the context of catalog item ?
I make sure the "applies on requested items" check box is true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 04:55 AM
An onLoad Catalog Client Script is a fine approach. If it's not working then your condition is not correct. Post the script attempt using the insert code </> icon and we'll get it sorted. You'll have to use GlideAjax to call a Script Include passing in the current user to determine if they are a member of a specific group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2024 09:18 PM
Write onLoad CCS
function onLoad(){
var grpId = 'sysid_group';
var ga = new GlideAjax('CheckUserGrp');
ga.addParam('name', "groupCheck");
ga.addParam('sys_id', grpId);
ga.getXMLAnswer(function(response) {
var isCheck = response.responseXML.documentElement.getAttribute('answer');
if (isCheck === 'true') {
g_form.setReadOnly("varibale", false);
} else {
g_form.setReadOnly("variable", true);
}
});
}
call script include
groupCheck: function() {
var userId = gs.getUserID();
var groupId = this.getParameter('sys_id');
var userGR = new GlideRecord('sys_user_grmember');
userGR.addQuery('user', userId);
userGR.addQuery('group', groupId);
userGR.query();
return userGR.next() ? 'true' : 'false';
}
});