Show list banner button based on HR Case state

rafas_10
Tera Guru

Hi everyone, hope you are doing well!

 

I am having a problem that I cannot set the visibility on my UI Action correctly. The button should only appear when the state is 18. The problem once again is that the button is working only when the state is 18 but it's appearing for every state. How can I fix this? It is a list banner button.

Condition:

RP.isRelatedList() && RP.getListControl().getControlID() == gs.getProperty('sn_hr_core.Create Child Case') && new HRCaseChecker().getHRCase(parent.sys_id)

 

Script include:

var HRCaseChecker = Class.create();
HRCaseChecker.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    initialize: function() {},

    getHRCase: function(sysId) {
        var gr = new GlideRecord('sn_hr_core_case');
        gr.addQuery('sys_id', sysId);
        gr.query();
		
        if (gr.next()) {
			gs.info("estou aqui "+gr.state);
            if (gr.state == '18') {
                return true;
				
            }
            return false;
        }
    },

    type: 'HRCaseChecker'
});
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@rafas_10 

are you getting the sysId in your function?

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
Tera Patron
Tera Patron

@rafas_10 

why not try this in condition itself?

RP.isRelatedList() && RP.getListControl().getControlID() == gs.getProperty('sn_hr_core.Create Child Case') && parent.state == "18"

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

It doesn't work, because I want the current state to be 18. The button is used to create a child case, so that condition won't work, and I can't use current.state because it's a list banner button placed on a related list, so It doesn't "fetch" the current.

 

Any other ideia @Ankur Bawiskar  🙂 ?

@rafas_10 

I think that's the limitation of list banner button that it cannot access current object

So this won't work

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