- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 06:45 AM
Hi guys,
Im trying to write a Client Script so that if a Problem has any open Tasks, a pop up appears saying 'You cannot close a Problem with open Tasks', please close out the corresponding tasks first'.
Below is the onSubmit Client Script I wrote on the Problem table but I cant get it to work.
Has anybody achieved this?
function onSubmit() {
//Type appropriate comment here, and begin script below
var id = g_form.getValue('number');
var close = g_form.getValue('state');
//If state changes to Closed, check if there is a related article
if (close == '4') {
var pt = new GlideRecord("problem_task");
pt.addQuery('source', id);
pt.addQuery('state', '1');
pt.query();
if (pt.next()) {
alert("test");
}
}
return false;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 06:51 AM
Hi Gerard,
How about a BEFORE business rule. Much simpler and faster.
Condition:
State | changes To | Closed
Script:
// This code is untested
(function executeRule(current, previous /*null when async*/) {
var pt = new GlideAggregate('problem_task');
pt.addAggregate('COUNT');
pt.addQuery('problem', current.getValue('sys_id'));
pt.addQuery('active', true);
pt.query();
if (pt.next()) {
count = pt.getAggregate('COUNT');
if (count > 0) {
gs.addErrorMessage('You cannot close this problem. It has active tasks.');
current.setAbortAction(true);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 08:38 AM
Apololgies, it does NOT actually close the ticket but does give the message to suggest it has.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 08:42 AM
Take a look at the Resolve Problem UI Action (or whatever it is called) and try moving the gs.addInfoMessage() to the end (somewhere after current.update()). The setAbortAction() is supposed to halt the update (commit) process.
If you can post the code to the UI action, I can make a more detailed analysis.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 08:55 AM
Gerard,
Add a condition before "gs.addInfoMessage('Problem ' + current.number + ' has been set to Close/Resolved');" as shown below and it should work now as expected.
Changes these 2 lines from
current.update();
gs.addInfoMessage('Problem ' + current.number + ' has been set to Close/Resolved');
to this
if(current.update())
gs.addInfoMessage('Problem ' + current.number + ' has been set to Close/Resolved');
Thanks,
Abhinay
Please mark Helpful, Like, or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 09:47 AM
Thanks everyone,
This is now working perfectly..
I really appreciate all the help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 07:52 AM
Gerard,
For the popup, you will have to go with onSubmit client script instead of business rule and use GlideAjax to do the manipulation on server side.
Thanks,
Abhinay
Please mark Helpful, Like, or Correct depending on the impact of the response