Make SCTASK variables editable to particular assignment group- Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hello All,
When a catalog item is requested, two different SCTASK records are generated — one assigned to Group A and the other to Group B.
If the logged-in user (or impersonated user) is a member of Group A, then the variables on the SCTASK assigned to Group A should be editable for that user.
At the same time, the same user must not be able to edit the variables on the SCTASK assigned to Group B.
Kindly suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @snehalkausa
Please try below steps:
- Navigate to your Catalog Item.
- In the "Variables" related list, open the variable you want to control.
- Go to the Variable Administration tab and ensure the Read only box is checked
Step 2: Create Display Business rule: Fill in the form with the following details:
- Name: Populate Scratchpad for SCTASK Variable Editability
- Table: Catalog Task [sc_task]
- When: Display
- Condition: current.assignment_group is not empty
Go to the Advanced tab and add the following script:
(function executeRule(current, previous /*null when async*/ ) { // Use gs.getUser().isMemberOf() to check if the current user is a member of the task's assignment group. g_scratchpad.isGroupMember = gs.getUser().isMemberOf(current.assignment_group.toString()); })(current, previous);
- Open the Catalog Item record.
- In the "Catalog Client Scripts" related list, click New.
- Fill in the form:
- Name: Control SCTASK Variable Editability
- Applies to: A Catalog Item (uncheck "Applies on a Catalog Item view" and "Applies on Requested Items").
- Type: onLoad
- Table: sc_task
- In the Script field, add the following code:
function onLoad() { // If the user is a member of the assigned group, make all variables editable. if (g_scratchpad.isGroupMember == true) { var allVariables = g_form.getEditableFields(); for (var i = 0; i < allVariables.length; i++) { g_form.setReadOnly(allVariables[i], false); } } }
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @snehalkausa
Use a UI Policy + Condition Script
You can create a UI Policy (or Client Script) on the sc_task form:
- Condition: Check if the current SCTASK’s assignment_group contains the logged-in user.
- Action: Make variables read-only unless the user belongs to that group.
Example condition script:
(function executeRule(current, gForm) {
var userID = gs.getUserID();
var groupID = current.assignment_group;
// Check if user is in the assignment group
var isMember = gs.getUser().isMemberOf(groupID);
if (!isMember) {
// Make variables read-only
g_form.setReadOnly('variable_name', true);
// repeat for all variables, or loop if many
}
})(current, gForm);
This ensures users outside the group see the variables as read-only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can use onLoad catalog client script + GlideAjax and check if logged in user is member of that group or not
this link has sample script
Is Memberof Group from Client side
Group-Based Variable Editing
Step 1: Create Script Include**
// Name: GroupMembershipUtils
isMemberOfGroup: function(userId, groupId) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group', groupId);
gr.query();
return gr.hasNext();
}
Step 2: onLoad Client Script (SCTASK Form)**
// Name: SCTASK Variable Access Control
// Table: sc_task
// Type: onLoad
function onLoad() {
// Get current user and assignment group
var userId = g_user.userID;
var assignmentGroup = g_form.getValue('assignment_group');
if (!assignmentGroup) return;
// Check group membership via GlideAjax
var ga = new GlideAjax('GroupMembershipUtils');
ga.addParam('sysparm_name', 'isMemberOfGroup');
ga.addParam('sysparm_user_id', userId);
ga.addParam('sysparm_group_id', assignmentGroup);
ga.getXMLAnswer(function(answer) {
var isMember = (answer === 'true');
// Make variables read-only if user not in assignment group
if (!isMember) {
makeVariablesReadOnly();
}
});
}
function makeVariablesReadOnly() {
// Get all variables on the form
var variables = g_form.getVariables();
for (var i = 0; i < variables.length; i++) {
g_form.setReadOnly(variables[i], true);
}
}
UI Policy Approach
// Create UI Policy on sc_task table
// Condition: javascript:!gs.getUser().isMemberOf(current.assignment_group)
// Action: Make variables read-only
Script Include
var GroupMembershipUtils = Class.create();
GroupMembershipUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isMemberOfGroup: function() {
var userId = this.getParameter('sysparm_user_id');
var groupId = this.getParameter('sysparm_group_id');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group', groupId);
gr.query();
return gr.hasNext().toString();
}
});