- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 04:18 AM
Hello Community
I want to set variables tab read only mode on ritm form for non admins to some specific catalog items.
As of now its is working correctly, But once Y task sets to closed complete on ritm form then only variables should be in read only mode. Now its working once ritm generated, the restrictions on this tab should only apply after this(Y) task is closed
How can we achieve this Here is the codes
Script include:
var MyGroups = Class.create();
MyGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isGrpMember:function() {
var userID = this.getParameter('sysparm_userID');
var groupID = this.getParameter('sysparm_groupName');
//get the group name based on the group id
gs.log("Entered the function of isGRP Member");
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id",groupID);
gr.query();
if (gr.next()) {
gs.log("Enered into the if condition of my script include");
var groupName = gr.getValue("name");
var thisUser = gs.getUser().getUserByID(userID);
if (thisUser.isMemberOf(groupName)) {
gs.log("Returned true becuase user is member of this group");
return true;
}
else {
gs.log("Returned false because user is not a member of this group");
return false;
}
} // end of if gr.next
},
type:'MyGroups'
});
Client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var item=g_form.getValue('cat_item');
if (item=='e7d48d55db5f8b00c77b7016bf96199b' || item=='e386bfb3dba68700c77b7016bf961943' || item =='ae244264dbb6c700c77b7016bf961944' || item== '1813429bdb83c700f3e5f156bf9619e9' || item== '0d0c3f5adb28e3001ac0105f6896198e' || item =='f2377d15db9f8b00c77b7016bf96191c' || item=='f477b155db9f8b00c77b7016bf961967')
{
//g_form.addInfoMessage("Entered into if condition");
var ga = new GlideAjax('MyGroups');
ga.addParam('sysparm_name', 'isGrpMember');
//ga.addParam('sysparm_userID', g_user.userID);
ga.addParam('sysparm_userID', g_user.userName);
ga.addParam('sysparm_groupName',g_form.getValue('assignment_group'));
ga.getXML(hideField);
//g_form.addInfoMessage("Entered into the function" +answer);
}
//g_form.addInfoMessage(g_user.hasRole('admin'));
function hideField (response) {
var answer = response.responseXML.documentElement.getAttribute('answer').toString();
//g_form.addInfoMessage("Entered into the function" +answer);
//g_form.addInfoMessage(g_user.hasRole('admin'));
if ((answer == 'false') && !g_user.hasRole('admin')) {
g_form.setVariablesReadOnly(true);
}
else
{
g_form.setVariablesReadOnly(false);
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 05:02 AM
Hi Nag,
I have updated the script. Check this once.
Script Include:
var MyGroups = Class.create();
MyGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isGrpMember:function() {
var userID = this.getParameter('sysparm_userID');
var groupID = this.getParameter('sysparm_groupName');
var req_item = this.getParameter('sysparm_reqItem');
//get the group name based on the group id
gs.log("Entered the function of isGRP Member");
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id",groupID);
gr.query();
if (gr.next()) {
gs.log("Enered into the if condition of my script include");
var groupName = gr.getValue("name");
var thisUser = gs.getUser().getUserByID(userID);
if (thisUser.isMemberOf(groupName)) {
gs.log("Returned true becuase user is member of this group");
return true;
}
else {
gs.log("Returned false because user is not a member of this group");
//check if any of the catalog tasks are complete.
return this._isCatalogTaskComplete(req_item);
}
} // end of if gr.next
else {
gs.log("Entered into else");
return this._isCatalogTaskComplete(req_item);
}
},
_isCatalogTaskComplete:function(req_item) {
//fetch the associated catalog tasks which are closed complete for this RITM
gs.log("Entered into the 2nd function");
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item",req_item);
gr.addQuery("state",3);
gr.query();
if(gr.next()) {
gs.log("Entered into if of 2nd function");
return false;
} else {
gs.log("Entered into else of 2nd function");
return true;
}
},
type:'MyGroups'
});
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var item=g_form.getValue('cat_item');
g_form.addInfoMessage("Entered onload function");
if (item=='e7d48d55db5f8b00c77b7016bf96199b' || item=='e386bfb3dba68700c77b7016bf961943' || item =='ae244264dbb6c700c77b7016bf961944' || item== '1813429bdb83c700f3e5f156bf9619e9' || item== '0d0c3f5adb28e3001ac0105f6896198e' || item =='f2377d15db9f8b00c77b7016bf96191c' || item=='f477b155db9f8b00c77b7016bf961967')
{
//g_form.addInfoMessage("Entered into if condition");
var ga = new GlideAjax('MyGroups');
ga.addParam('sysparm_name', 'isGrpMember');
//ga.addParam('sysparm_userID', g_user.userID);
ga.addParam('sysparm_userID', g_user.userName);
ga.addParam('sysparm_groupName',g_form.getValue('assignment_group'));
ga.addParam('sysparm_reqItem', g_form.getUniqueValue());
ga.getXML(hideField);
//g_form.addInfoMessage("Entered into the function" +answer);
}
//g_form.addInfoMessage(g_user.hasRole('admin'));
function hideField (response) {
var answer = response.responseXML.documentElement.getAttribute('answer').toString();
g_form.addInfoMessage("Entered into the function" +answer);
if ((answer == 'false') && !g_user.hasRole('admin')) {
g_form.setVariablesReadOnly(true);
}
else
{
g_form.setVariablesReadOnly(false);
}
}
}
Mark the comment as a correct answer and also helpful once worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 06:00 AM
Okay.
Kindly mark the comment as a correct answer and also helpful once worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 06:01 AM
Thanks a lot asif its working for other users also, Finally its worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 02:57 PM
At one point there were several posts about g_form.setVariablesReadOnly(true) not being supported by SN and to use at your own risk... is this now supported by SN?