Need to restrict/hide variable section from RITM

Joyal
Tera Contributor

Hi All,

We have a requirement in order to hide variable section from the RITM for all the users except members from the group 'abc' for the catalog item 'Support'.

 

Step 1: Need to check the cat_item field value is 'Support'
Step 2: check the current user who loads/opens the form is member of the group 'abc'
Step 3: If yes, then he should be able to see the variable section
Step 4: If no, then the variable section and the variable fields inside the variable section should not be visible

Joyal_0-1735313335637.png

 


Please help me on this.

Thanks,
Joyal Robert

6 REPLIES 6

Juhi Poddar
Kilo Patron

Hello @Joyal 

This can be useful: Hide a variable in RITM

The above post shows how we can hide particular variable in ritm. 

A bit of workaround can help you to meet your requirement.

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Hi @Juhi Poddar 

 

Actually what i am looking here is that only members in the group should be able to see the Variable section apart from that any other shouldn't be able to view the variable section entirely

Thanks, 

Joyal Robert

Ankur Bawiskar
Tera Patron
Tera Patron

@Joyal 

it should be an easy onLoad client script on sc_req_item table + Display BR on sc_req_item

Display BR:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.isMember = gs.getUser().isMemberOf('group ABC'); // give the group name here

})(current, previous);

onLoad client script

Ensure Isolate Script field is False to allow DOM to run the client script

This field is not on form but from list you can make it false

function onLoad(){

if(g_form.getValue('cat_item') == 'catItemSysId' && g_scratchpad.isMember.toString() == 'true'){

// use DOM manipulation to hide the section
}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

I had written the below scripts:
script include:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendObject(AbstractAjaxProcessor, {

    checkIfUserIsInGroup: function() {
        var userID = this.getParameter('sys_id');
        var groupID = this.getParameter('group');

        var userGroup = new GlideRecord('sys_user_grmember');
        userGroup.addQuery('user', userID);
        userGroup.addQuery('group', groupID);
        userGroup.query();

        if (userGroup.next()) {
            return 'true';
        } else {
            return 'false';
        }
    }
});

Onload Client Script:
function onLoad() {
    var catalogItem = g_form.getValue('cat_item');

    var supportCatalogItemSysId = '81b059c91bbe421083bf86afdc4bcb5f';
    if (catalogItem == supportCatalogItemSysId) {
        var groupID = '5f0ee3b78743e910f956c88e8bbb3789';
        var userIsInGroup = checkIfUserIsInGroup(groupID);
        if (!userIsInGroup) {
            hideVariableEditor();

        }
    }
}

function checkIfUserIsInGroup(groupID) {
    var isInGroup = false;
    var ga = new GlideAjax('CheckUserGroup');
    ga.addParam('sys_id', g_user.userID);
    ga.addParam('group', groupID);
    ga.getXMLAnswer(function(response) {
        var isInGroup = response.responseXML.documentElement.getAttribute("answer");
    });
    return isInGroup;
}

function hideVariableEditor() {

    var variableMap = document.getElementById('variable_map');
    if (variableMap) {
        variableMap.style.display = 'none';
        var items = variableMap.getElementsByTagName('item');
        for (var i = 0; i < items.length; i++) {
            items[i].style.display = 'none';
        }
    }
}

I was not able to get the expected result. Could you please help me on to fix the issue?

Thanks,
Joyal Robert