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

J Siva
Tera Sage

Hi @Ore-Jon 
Try the below script. Also, share the picture of your UI Action configuration.

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

Regards,
Siva

 

Ore-Jon
Tera Contributor

@J Siva thank you for the suggestion. I tried it with the current conditions and it is hiding the button on all RITM's now.

 

UI Action Condition:

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

Mark Manders
Mega Patron

To start with: are the sysIDs the correct ones? 

And what's the condition on the UI action itself? You are calling a 'hide' function to hide it on 3 items and return 'false'. Although it may give the correct result, I would expect a true, because it's called 'hide'. This is more about the logic in the thought process, then technical execution, but if you are updating it, maybe reverse it or call it 'show' instead of 'hide'.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders yes, verified the sysIDs are the correct ones.

 

This is the current condition:

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