Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Action Button - How to hide/show button based on conditions for Demand form

Brandon26
Tera Contributor

I need to hide the Qualify UI action button on a Demand form if the Stakeholder related list is empty, and display a message that at least one stakeholder needs to be added before it can be qualified. 

Does anyone know how I can accomplish this??

Thanks,

Brandon

 

1 ACCEPTED SOLUTION

Sure so you could create a new script include as below:

find_real_file.png

Script:

var demandUtils = Class.create();
demandUtils.prototype = {
    initialize: function() {},

    checkStakeholders: function(dmnd) {
        var stakeholderRelGr = new GlideRecord('dmn_m2m_demand_stakeholder');
        stakeholderRelGr.addQuery('demand', dmnd);
        stakeholderRelGr.query();
        return stakeholderRelGr.hasNext();
    },

    type: 'demandUtils'
};

Then you could set the Condition field on your Qualify UI action as below to conditionally display based on whether there are any stakeholders for the current Demand record:

new global.demandUtils().checkStakeholders(current.getUniqueValue())

And for the message to display at the top you could create a new Display business rule as below:

find_real_file.png

find_real_file.png

Condition:

!new global.demandUtils().checkStakeholders(current.getUniqueValue())

Script:

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

	// Add your code here
	gs.addInfoMessage('At least one Stakeholder needs to be added before Demand can be qualified');

})(current, previous);

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

8 REPLIES 8

Hey Brandon,

I mentioned that part in my answer above, specifically this:

Then you could set the Condition field on your Qualify UI action as below to conditionally display based on whether there are any stakeholders for the current Demand record:

new global.demandUtils().checkStakeholders(current.getUniqueValue())

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

I think I noticed that after I replied, and realized I did not word my issue correctly.

I modified the Qualify UI action with the condition above and it works, but not sure what condition to use now to hide the Qualify button at the Draft/Submitted/Screening state when there is no stakeholder listed.

Basically, if the Demand is promoted to the Screening state then I add a stakeholder, the Qualify button should display once a stakeholder is added. Do you know what needs to be added to the Condition to make that happen??

Could you share screenshots of the steps you're describing? If there are any stakeholders for the demand then the button should be visible, but what you're describing makes me think that when you're adding the stakeholder the Demand form is not yet refreshed with updated data from the server to tell ServiceNow that yes, there is a stakeholder for this demand so we should show the qualify button.

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Hi Chris, I think I figured it out. What I ended up doing was removing the current.state == 2 || current.state == 3 conditions and it worked the way I needed.

find_real_file.png