Change and Change Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2015 08:33 AM
Hello All,
I have a requirement which is related to Change and Change task
Scenario:
Considering an example:
I have a change request and I have 8 associated CTASKS as well. When I "Close Complete" the change request some 4 out of 8 Open CTASKS should get " Close Skipped".
If the change request has remaining 4 open CTASKS, it shouldn't allow the change to get close and I am expecting a pop up message stating that "Open CTASKS are present and you can't close the change)
Is this possible? If yes how can I achieve this?
Your response will be very much appreciated.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 12:09 AM
Good Morning Peggy,
Thank you for the above clarification!
Well, looking at the original script of the BR, which you pasted above - I may say that it looks fine.
It's the same great script of Suraj!
So, I continue to believe that your problem comes from the change statuses you have.
You may try playing also with this line of code: " target.addQuery('state', 1);".
Using Sujar's original script and changing only this line of it: "if ((current.state == 4) || (current.state == 3)){" allows me to complete your scenario.
Thus I am on the opinion that the states you are using for the Change Request are making the issue.
Or, the one for the Change Task, as you are using 1 there which equals "Waiting". Why don't you try with "New" also?
If possible reset, to say so, the values to the original statuses and use the following script in your BR, for testing purposes:
(function executeRule(current, previous /*null when async*/) {
// This Business Rule prevents a Change Request (change_request) (CHG) record to be closed if it has one or more opened Change Tasks (CTASK) in it, and also puts a notification saying that there is / are open task(s) in the change due to which it cannot be closed;
var gr = new GlideRecord('change_task');
gr.addQuery('change_request', current.sys_id);
// The line below - Select the state from Change Task which you need to query;
gr.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5); // "Waiting", "Work In Progress", "New";
gr.query();
if(gr.hasNext()){
// The line below - Check if state of Change Request changes to "Canceled" / "Closed";
if ((current.state == 4) || (current.state == 3)){
gs.addInfoMessage("You cannot close this Change Request due to open Change Task in it");
current.setAbortAction(true);
}
}
})(current, previous);
Best Regards,
Georgi Mavrodiev
IT Consultant
Do IT Wise
You may visit us in our Web Site: www.doitwise.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 11:12 AM
Hi Georgi,
I am trying to do the same thing and am running into some trouble as well.
What i would like to happen is:
IF Change Task is Open, Work in Progress, or Pending
and Change State is "Review" -- Give error message.
____________________
Table: Change request
When: Before (insert and Update)
Script:
function onBefore(current, previous) {
var target = new GlideRecord('change_task');
target.addQuery('change_request', current.sys_id);
//search for open Change tasks - select the state from change task which you need to query
target.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5);
target.query();
if(target.hasNext()){
// check if state of change request changes to Closed
if (current.state == 0){
gs.addInfoMessage("You have open tasks which must be completed before this record can be closed");
current.setAbortAction(true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2017 11:56 PM
Hello Zachary,
In your above post, you did not mention what exactly the problem with the BR is.
Anyway, if you are trying to achieve exactly the same outcome as Peggy and you are testing the BR pasted earlier -> then, first ensure you are using the correct values of your Change Tasks' states in the script. Secondly, I would do the following change in the Business Rule of yours -> it will be to change the Filter Condition of it to State | changes to | Closed instead of State | is | Review. After that everything should be OK and your goal will be covered.
&
Regards,
Georgi Mavrodiev
IT Consultant
Do IT Wise
You may visit us in our Web Site: www.doitwise.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 08:09 AM
Hi Georgi,
I have your code with an OOTB instance ( I have actually tried multiple instances with no luck) and still do not see the Business Rule run. I was able to close the Change without completing the tasks and no message appeared.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 03:34 AM
Hello Zachary,
I've tested the code on another Jakarta DEV instance and I do not encounter your problem. It runs fine.
So, if I were you - I would do the following. Firstly, I would try to run the Business Rule by putting the state choices' values in ' '. For example: '-5' and etc.
Secondly (if the first option does not help), I would start debugging the Business Rule, by adding gs.info and etc. into its code lines to see where the trouble - maker lies.
Best Regards,
Georgi Mavrodiev
IT Consultant
Do IT Wise
You may visit us in our Web Site: www.doitwise.com