Is there a Way to Make MVRS variables editable on SCTASK for a particular group?

saint
Tera Expert

Hi Experts,

 

I have a MVRS, which lets requestor select user values from user table. This item creates a tasks which passes through diff teams, and teams can edit the variables in from on the users to update the information/ input the information, and then close the task.

 

UserIDNew Manager New LaptopNew XYZNew ABC.....
Selected at form submissionselected at sctask for group HRselected at sctask for group ITselected at sctask for group XYZselected at sctask for group ABC.....

 

Please let me know the configurations i can do to achieve this result.

 

Regards,

2 REPLIES 2

Gaurav Vaze
Kilo Sage
Create a script include first to be called from client script
 
var UserGroupCheck = Class.create();
UserGroupCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkMembership: function() {
        var groupName = this.getParameter('sysparm_group_name');
        var userId = gs.getUserID();
        
        if (gs.getUser().isMemberOf(groupName)) {
            return "true";
        }
        return "false";
    },

    type: 'UserGroupCheck'
});

2] We need to create client script to call SI we created

Open the variable set

in the catalog client script tab, clieck on new

select Type OnLoad

Applies to All

 

This script runs when the form loads, calls the Script Include above, and then locks or unlocks the Multi-Row Variable Set (MRVS) based on the result.

  • Type: onLoad

  • UI Type: All

JavaScript
 
function onLoad() {
    var ga = new GlideAjax('UserGroupCheck'); // Name of the Script Include
    ga.addParam('sysparm_name', 'checkMembership'); // Name of the function
    ga.addParam('sysparm_group_name', 'Security Team'); // Replace with your group name
    
    ga.getXMLAnswer(handleResponse); // Asynchronous callback

    function handleResponse(response) {
        // If response is not "true", make the MRVS read-only
        if (response !== "true") {
            // Replace 'my_mrvs_internal_name' with your actual MRVS internal name
            g_form.setReadOnly('my_mrvs_internal_name', true);
        }
    }
}

 

NOte: This is just example. kindly update as per your need
Please mark he solution as helpful if it helped you
And accept as solution

Thank you!
Gaurav Vaze

ServiceNow Developer

Thank you for your response @Gaurav Vaze , 

I can make the entire MVRS editable, but i want to achieve a way where one group can edit one varibale from the MVRS and for other teams it becomes read-only, for security. Thanks again for your detailed response and script.