Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Make catalog variables editable for a particular group memebers

roomawakar
Tera Contributor

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,

 

10 REPLIES 10

GlideFather
Tera Patron

Hi @roomawakar,

 

just on the very first sight, you can try to remove the quotes in Script include returns:

return true; //not 'true'
return false; //not 'false'

 

And let me know if that helped 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@roomawakar 

you can do it using display BR and scratchpad:

https://www.servicenow.com/community/developer-forum/allow-a-group-to-edit-a-variable-in-variable-ed...

 

or:

https://www.servicenow.com/community/developer-forum/how-to-make-catalog-variable-editable-on-ritm/m...

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hi,

Solution didn't work.

 

Thanks,

Rooma

RaghavSh
Mega Patron

g_form.getValue("cat_item") == "d025b6ff870ce950fa770d47cebb3566" , you have used this, does this mean you have written the client script on RITM table? or it is a catalog client script?

 

In case this is a client script on RITM table, use the below to make variables readonly true and false:

 

g_form.setReadOnly('variables.<variableName>', true);


Raghav
MVP 2023
LinkedIn