- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:36 AM
Hi all,
I have an urgent requirement
I have to create an UI action button name as 'close' on 'Issue table' that should be visible to only users having some role. when state is resolved in issue table. It should check that all the related "issue tasks"(child table of issue table) should be closed before closing the issues. If all the tasks are closed issues should also be closed.
I tried the code below but it is not working as expected
Condition - gs.hasRole('issue_mgmt_worker')
code-
var rec = new GlideRecord('u_issue_task');
rec.addQuery('u_parent_issues', current.sys_id);
rec.addQuery('state', '3');
rec.query();
if(rec.next()){
gs.addErrorMessage('All issue taks should be closed before resolving/closing issue ' + current.number + ' record'); // use valid number field
current.setAbortAction(true);
}
else
{
current.state='3';
current.update();
}
action.setRedirectURL(current);
Solved! Go to Solution.
- Labels:
-
Major Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:49 AM
Hi Vijay,
Did you try adding logs to check till where it is working fine
Check is the number field a valid field?
Should it not be u_number since it is your custom table
var rec = new GlideRecord('u_issue_task');
rec.addQuery('u_parent_issues', current.sys_id);
rec.addQuery('state', '3');
rec.query();
gs.info('Open Issue Tasks' + rec.getRowCount());
if(rec.next()){
gs.info('Inside if');
gs.addErrorMessage('All issue taks should be closed before resolving/closing issue ' + current.number + ' record'); // use valid number field
current.setAbortAction(true);
}
else
{
current.state = '3';
current.update();
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:40 AM
I think you need to check if the state is not 3, try the below code:
var rec = new GlideRecord("u_issue_task");
rec.addQuery("u_parent_issues", current.sys_id);
rec.addQuery("state", "!=", "3");
rec.query();
if (rec.next()) {
gs.addErrorMessage(
"All issue taks should be closed before resolving/closing issue " +
current.number +
" record"
); // use valid number field
current.setAbortAction(true);
} else {
current.state = "3";
current.update();
}
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:41 AM
1 u_parent_issues should be a reference field
2. rec.addQuery('state', '3'); in this line 2 should be without '' as state is an integer field.
Raghav
MVP 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:40 AM
It sounds like you want to check if there are any open tasks, and if so abort the action and give the user a message. In your code you're checking for closed tasks instead. You might change the state query line to:
rec.addQuery('state', '!=', '3');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:49 AM
Hi Vijay,
Did you try adding logs to check till where it is working fine
Check is the number field a valid field?
Should it not be u_number since it is your custom table
var rec = new GlideRecord('u_issue_task');
rec.addQuery('u_parent_issues', current.sys_id);
rec.addQuery('state', '3');
rec.query();
gs.info('Open Issue Tasks' + rec.getRowCount());
if(rec.next()){
gs.info('Inside if');
gs.addErrorMessage('All issue taks should be closed before resolving/closing issue ' + current.number + ' record'); // use valid number field
current.setAbortAction(true);
}
else
{
current.state = '3';
current.update();
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader