- 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-25-2022 09:41 AM
You will need a script include function which returns true/false depending on if there are any Stakeholders for the current Demand record. You can then call the script include function from the UI action's condition field so that it displays based on whether the script include returns true/false.
For displaying the message that at least one stakeholder needs to be added, you can use a Display business rule which references the same script include function from above.
Hopefully that makes sense, I can provide more details if needed.
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-25-2022 09:50 AM
I'm new to javascripting. How do you write that kind of script include??
- 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 10:06 AM
Thanks for all this!
To take this a step further, how can I configure the Qualify UI action button to NOT display if there are no stakeholders?? Maybe using OnClick??
