The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Make a catalog variable editable based on script condition

Mohamed Taha
Tera Expert

in catalog item , i want to make a variable be editable after submitting the request ( on requested item ) if the user is a member of specific group group

i make a catlog client script to evaulate the condition and if the condition is true i use this statement 

g_form.setReadOnly("variable_name",false);

but nothing changes , I'm asking is this method available in the context of catalog item ?

 

I make sure the "applies on requested items" check box is true.

 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

An onLoad Catalog Client Script is a fine approach.  If it's not working then your condition is not correct.  Post the script attempt using the insert code </> icon and we'll get it sorted.  You'll have to use GlideAjax to call a Script Include passing in the current user to determine if they are a member of a specific group.

Mani A
Tera Guru

Write onLoad CCS

 

function onLoad(){

 

    var grpId = 'sysid_group';

    

    var ga = new GlideAjax('CheckUserGrp');

ga.addParam('name', "groupCheck");

    ga.addParam('sys_id', grpId);

    ga.getXMLAnswer(function(response) {

        var isCheck = response.responseXML.documentElement.getAttribute('answer');

        if (isCheck === 'true') {

            g_form.setReadOnly("varibale", false);

        } else {

            g_form.setReadOnly("variable", true);

        }

    });

}

 

call script include

 

    groupCheck: function() {

        var userId = gs.getUserID();

        var groupId = this.getParameter('sys_id');  

        var userGR = new GlideRecord('sys_user_grmember');

        userGR.addQuery('user', userId);

        userGR.addQuery('group', groupId);

        userGR.query();        

        return userGR.next() ? 'true' : 'false';

    }

});