- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 08:19 AM
Hi community,
I am trying to close all the change tasks open for any change request that reaches the Review state.
I will not change the workflow to have a script include since I only want for this to happen to certain changes, in this case for the ones I have an Integration with Remedy.
The state in the change workflow is controlled by UI Action, this means that to change the state, it needs to be done manually.
In the case of the integration, we receive a message that automatically change the state to Review. Review is the last state of the workflow.
I have tried to include a BR to have the tasks closed but it seems that it is not working, and I think it should... since I have picked up the code we have on wiki.
BR: onBefore
Table: change_request
var ctask = new GlideRecord('change_task');
ctask.addQuery('change_request', current.sys_id);
ctask.query();
while(ctask.next()){
ctask.state.setValue(3);
ctask.work_notes = "Task automatically closed";
}
current.work_notes = "Tasks automatically closed";
Instead of having the "Closed" state I have "Closed Incomplete".
Any idea of why this is happening?
Thank you in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 04:01 AM
I've found a solution for this.
Dumb mistake, it was only missing a ctask.update(); inside the while loop.
All working now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 08:22 AM
Hello Hugo,
I see that your BR is an onBefore. Isn't it should be an after or async BR script because you want to close a task once it reaches Review state? Also, specifically the check the order value of your script comparing with one which changes the state to Review. The order of scripts plays a crucial role when it involves workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 08:47 AM
I have tried to change it to OnAfter and I have the same result, "Closed Incomplete".
Also the work note is not showing in the ctask.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 02:10 PM
Hello Hugo,
I am pretty sure that it should work with an onAfter business rule script. Have you tried adding the debug logs to verify the flow of your script? When I say debug logs, I mean using gs.log statements that will help.
Also try replacing the script state "ctask.state.setValue(3);" with "ctask.state = '3';" and check if that makes any difference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 08:31 AM
Hi,
Please check the choices values for change_request by opening a change ticket - > (On state dropdown > show choice) -> check appropriate value for closed.
Code looks good to me,
Thanks,
Best Regards,
Rajeev Saraf