How to check the Task close before closing the Change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 01:16 PM
Hi All,
We need to close all the tasks where short description of Task contain the string "Dupicate Change Task"
Basically if the Tasks associated with the change are active and Short description = %Dupicate Change Task% then thease task should be closed then only system allow change to move to the next stage.
Need to do it using UI action.How to achive this.
Thanks in advance.
addQuery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 01:18 PM
You can configure business rule on change_task to close change task with required description.
Also, you can move change to next stage after change task is closed in business rule script.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 01:20 PM
Hi Navneet,
You can pretty much do a GlideAjax call, check if there is any open records, if there is, abort the save and put up error message. Otherwise save.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 01:25 PM
Thanks Sachin and Goran for your quick response.
Here want to do it using the UI action and how could i check for open task and Short description string?
any Sample code?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 01:38 PM
Please check below sample code for checking any open tasks for change
You can put this code in script include and call this script include from UI action.
This is business rule code but you can tweak it to repalce with Glideobject .
var temp = 0;
var task = new GlideRecord('change_task');
task.addQuery('u_type','close');
task.addQuery('change_request',current.sys_id);
task.query();
if(task.next())
{
if(task.state == 1)
{
temp = 1;
}
else
{
temp = 0;
}
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request',current.sys_id);
cTask.addQuery('wf_activity','');
cTask.addQuery('state',1);
cTask.query();
if(cTask.next())
{
temp = 1;
}
var cAssess = new GlideRecord('u_change_assessment');
cAssess.addQuery('u_change_request', current.sys_id);
cAssess.addQuery('state',1);
cAssess.query();
if(cAssess.next())
{
temp = 1;
}
}
else
{
/*if(current.type != 'Emergency')
{*/
var task1 = new GlideRecord('change_task');
task1.addQuery('u_type','implementation');
task.addNotNullQuery('wf_activity');
task1.addQuery('change_request',current.sys_id);
task1.addQuery('state',3);
task1.query();
if(task1.next())
{
temp = 2;
}
else
{
temp = 0;
}
/*
}
else
{
temp = 2;
}
*/
}
if(temp == 1)
{
current.state = previous.state;
gs.addInfoMessage("Change cannot be closed due to outstanding open task(s).");
current.setAbortAction(true);
}
if(temp == 2)
{
current.state = previous.state;
gs.addInfoMessage("Change has been implemented and can no longer be cancelled.");
current.setAbortAction(true);
}
Regards,
sachin