From a64c2a155d17365debeb4b6c96c3e99b223e0f90 Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:33:01 +0530 Subject: [PATCH 1/3] Create Set_and_Lock_Variable_by_Group --- .../Set_and_Lock_Variable_by_Group | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Set and Lock variable by Group/Set_and_Lock_Variable_by_Group diff --git a/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/Set_and_Lock_Variable_by_Group b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/Set_and_Lock_Variable_by_Group new file mode 100644 index 0000000000..05056c2851 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/Set_and_Lock_Variable_by_Group @@ -0,0 +1,20 @@ +function onLoad() { + var variableName = 'bypass_approval_reason'; + var targetGroupName = 'ServiceNow Support'; // The group authorized to skip this step + var ga = new GlideAjax('UserUtils'); + ga.addParam('sysparm_name', 'isMemberOf'); + ga.addParam('sysparm_group_name', targetGroupName); + ga.getXMLAnswer(checkAndLockVariable); + function checkAndLockVariable(response) { + var isMember = response; + if (isMember == 'true') { + var message = 'Value set and locked due to your ' + targetGroupName + ' membership.'; + var setValue = 'Bypassed by authorized ' + targetGroupName + ' member.'; + g_form.setValue(variableName, setValue); + g_form.setReadOnly(variableName, true); + g_form.showFieldMsg(variableName, message, 'info'); + } else { + g_form.setReadOnly(variableName, false); + } + } +} From 89850932d71786eb21897fdb78a37247ec3f95a2 Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:35:39 +0530 Subject: [PATCH 2/3] Create UserUtils --- .../Set and Lock variable by Group/UserUtils | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Set and Lock variable by Group/UserUtils diff --git a/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/UserUtils b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/UserUtils new file mode 100644 index 0000000000..617f9dcc13 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/UserUtils @@ -0,0 +1,10 @@ +var UserUtils = Class.create(); +UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { + isMemberOf: function() { + var groupName = this.getParameter('sysparm_group_name'); + var isMember = gs.getUser().isMemberOf(groupName); + return isMember.toString(); + }, + + type: 'UserUtils' +}); From dfc24094e960732b2389c464a20d5c2d3e89a78a Mon Sep 17 00:00:00 2001 From: MANCHALA YASWANTH <71426465+MYaswanth28@users.noreply.github.com> Date: Thu, 16 Oct 2025 13:23:20 +0530 Subject: [PATCH 3/3] Create README.md --- .../Set and Lock variable by Group/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Set and Lock variable by Group/README.md diff --git a/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/README.md b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/README.md new file mode 100644 index 0000000000..e7d932757d --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Set and Lock variable by Group/README.md @@ -0,0 +1,5 @@ +**Set and Lock Variable by Group** + +This solution provides a secure and dynamic way to control data entry on a Service Catalog form based on the user's group membership. It is typically used to pre-fill and lock certain justification or approval bypass fields for authorized users (like managers or executive staff), improving their efficiency while maintaining an accurate audit trail. + +This functionality requires a combined Client-side (Catalog Client Script) and Server-side (Script Include) approach to ensure the group check is done securely.