UI Action - Hide Button on Conditions

Ore-Jon
Tera Contributor

Hi. We are trying to fix a broken Script Includes the vendor left behind. It is supposed to hide the Close button on a RITM record based on State and to hide it for 3 specific Catalog Items. It is a script include on a UI Action. Right now, it's hiding the button for all records as it seems to result in False. If I comment out just that section, it shows for all records again.

 

var HideButtonsInRITM = Class.create();
HideButtonsInRITM.prototype = {
    initialize: function() {
    },
    hideClosedButtons: function(ritm_id) {
        var gr = new GlideRecord('sc_req_item');
        gr.addEncodedQuery    ('cat_item=43961e361badc6906ef37cd61a4bcbc4^ORcat_item=44188dee1b6d4a50c00fec21b24bcb94^ORcat_item=89df48e01b71c2d06ef37cd61a4bcbeb');
        gr.query();
        while(gr.next()) {
            return 'false';
        }
        return 'true';
    },
    type: 'HideButtonsInRITM'
};
1 ACCEPTED SOLUTION

Hi @Ore-Jon ,

 

update your script include as

var HideButtonsInRITM = Class.create();
HideButtonsInRITM.prototype = {
    initialize: function() {},
    hideClosedButtons: function(ritmGr) {
        var arr = ['43961e361badc6906ef37cd61a4bcbc4', '44188dee1b6d4a50c00fec21b24bcb94', '89df48e01b71c2d06ef37cd61a4bcbeb'];
        return !arr.includes(ritmGr.getValue('cat_item'));

    },
    type: 'HideButtonsInRITM'
};

and UI action condition as

(current.state == 1 || current.state == 2) && new global.HideButtonsInRITM().hideClosedButtons(current);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Ore-Jon 

update as this and use the optimized one

I hope you are invoking it in UI action condition like this

new HideButtonsInRITM().hideClosedButtons(current.cat_item.sys_id)

var HideButtonsInRITM = Class.create();
HideButtonsInRITM.prototype = {

    initialize: function() {},

    hideClosedButtons: function(ritm_id) {
        var sysIdArr = ['43961e361badc6906ef37cd61a4bcbc4', '44188dee1b6d4a50c00fec21b24bcb94', '89df48e01b71c2d06ef37cd61a4bcbeb']
        var rec = new GlideRecord('sc_req_item');
        rec.addEncodedQuery('cat_item.sys_idIN' + sysIdArr.toString());
        rec.query();
        return !rec.hasNext();
    },
    type: 'HideButtonsInRITM'
};

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

@Ankur Bawiskar 

This resulted in the same, where the button is hidden for all catalog items.

The UI Condition was:

((current.state == 1 || current.state == 2) &&( new global.HideButtonsInRITM().hideClosedButtons(current.sys_id) == 'true'))

 

I tried your suggestion for changing both, the UI Condition and the Script include, but it's hiding the button on all RITM's. 

Hi @Ore-Jon ,

 

update your script include as

var HideButtonsInRITM = Class.create();
HideButtonsInRITM.prototype = {
    initialize: function() {},
    hideClosedButtons: function(ritmGr) {
        var arr = ['43961e361badc6906ef37cd61a4bcbc4', '44188dee1b6d4a50c00fec21b24bcb94', '89df48e01b71c2d06ef37cd61a4bcbeb'];
        return !arr.includes(ritmGr.getValue('cat_item'));

    },
    type: 'HideButtonsInRITM'
};

and UI action condition as

(current.state == 1 || current.state == 2) && new global.HideButtonsInRITM().hideClosedButtons(current);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Chaitanya ILCR
Kilo Patron

Hi @Ore-Jon 

 

update your script include as

 

var HideButtonsInRITM = Class.create();
HideButtonsInRITM.prototype = {
    initialize: function() {},
    hideClosedButtons: function(ritmGr) {
        var arr = ['43961e361badc6906ef37cd61a4bcbc4', '44188dee1b6d4a50c00fec21b24bcb94', '89df48e01b71c2d06ef37cd61a4bcbeb'];
        return !arr.includes(ritmGr.getValue('cat_item'));

    },
    type: 'HideButtonsInRITM'
};

 

and UI action condition as

 

(current.state == 1 || current.state == 2) && new global.HideButtonsInRITM().hideClosedButtons(current);

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya