
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 07:55 AM
Afternoon all,
I am trying to add an additional control into a Close UI action script to check if a demand record has any pending decisions (decisions need to be state = approved or rejected), but as soon as I add the code the Close button fails to execute. The code is literally a copy of an Approve UI Action script earlier in the process, so field names and values are correct). Can anyone explain why this addition in blue stops the Close execution please.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 09:02 AM
Hi @Cirrus ,
Your blue line code(Server side) must be inside function definition closeDemand() i.e
function closeDemand() {
//here
var grDecision = new GlideRecord('dmn_decision');
grDecision.addQuery('parent', current.sys_id);
grDecision.addQuery('state', '-5'); // Pending
grDecision.query();
// Only close if there are no pending decisions
if (grDecision.next()) {
gs.addErrorMessage('A Demand cannot be closed whilst Decisions are still pending');
return;
}
current.state = '9';
current.update();
action.setRedirectURL(current);
}
beacuse its client side UI action using gsftSubmit function to execute serverside code.
Hope this helps!!!
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 09:02 AM
Hi @Cirrus ,
Your blue line code(Server side) must be inside function definition closeDemand() i.e
function closeDemand() {
//here
var grDecision = new GlideRecord('dmn_decision');
grDecision.addQuery('parent', current.sys_id);
grDecision.addQuery('state', '-5'); // Pending
grDecision.query();
// Only close if there are no pending decisions
if (grDecision.next()) {
gs.addErrorMessage('A Demand cannot be closed whilst Decisions are still pending');
return;
}
current.state = '9';
current.update();
action.setRedirectURL(current);
}
beacuse its client side UI action using gsftSubmit function to execute serverside code.
Hope this helps!!!
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 09:33 AM
Thanks Hemanth,
I will test this in the morning, but just to clarify, we want the close function to first check if there are outstanding decisions and then check if the close notes and reason have been completed, so are we mixing server and client side here?? Would your code not update the demand state based on decision state alone?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 09:45 AM
Hi @Cirrus ,
If you would like to check outstanding decisions first then approach would be different.
1)First use glideAjax to send current record sys_id and find if any pending decisions in a script include if yes return false - this becomes client side call.
2) If no Use existing logic (g_form) to check close notes.
3)If both looks good> go to Server side and update/close the demand.
Let me know if you need script for this or you would like to try first.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 06:08 AM
Thanks again Hemanth,
Your original advice has provided a workable solution, as the order of checking is not critical. I will look in slower time to try the glideAjax solution as it might provide a better experience, otherwise the user has to save the closure notes before closing, if there is still an open decision, otherwise the initial input is lost