- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 09:27 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 10:37 AM
Sure so you could create a new script include as below:
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:
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
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 11:09 AM
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
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 12:42 PM
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??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 01:47 PM
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
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 10:49 AM
