- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 07:38 AM
Hello all,
I have a custom choice of "Implement" in the Change Task State field.
I had a requirement to ensure that once a user opens a Change Request record, which is in "Scheduled" State and goes to the Change Tasks Related List and changes the states of all the Change Tasks presented there to "Implement" -> then, automatically the Change Request itself will be moved to "Implement" State.
I was able to cover this goal by creating a Business Rule against Change Task (change_task) table. It works perfectly, but it does not refresh the page once it finishes its work.
In other words I see the following once the States of all related Change Tasks were moved to "Implement", and I need to reload the form of the Change Request in order for the change in the State field to be updated:
I already tried couple of approaches and the result continues to be negative.
So, could you please provide me with a line of code which can be executed at the end of the Business Rule and to refresh the page? Thank you!
Regards, Georgi
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 08:21 AM
It was my understanding that a Change Manager would be manually setting the Tasks associated with the change to have the Implement State. This is why I proposed using the Wait condition within the workflow. It appears that once all of the related tasks are in Implementation State, the Change Request should then be in Implement state. If this is your business process, then we should be able to leverage a Business Rule and a Wait condition.
1. Business rule: Set Change when State is Implement
- Create an onAfter business rule that runs when the state changes to Implement
- This will 'touch' the Change record so that the Wait condition will re-check.
- I will use the state value of 10 in my example since I do not know what your Implement state is.
- Here is a sample code:
Condition: current.state.changesTo(10)
Script:
(function executeRule(current, previous /*null when async*/) {
var notesTxt = 'Change Task ' + current.number + ' set to: ' + curent.state.getDisplayValue();
var chgObj = new GlideRecord('change_request');
chgObj.get(current.change_request);
chgObj.work_notes = notesTxt;
chgObj.update();
})(current, previous);
2. Script Include: ChangeUtils
- As of Geneva, there is an existing Script Include that can be used with Change Request: ChangeUtils
- Adding additional methods to this Script Include will allow you to call it from within any workflow.
- Having your script outside of the workflow allows you to edit the function without having to check out the workflow.
- Below are two methods you can add to this Script Include:
closedTasks: function(chgObj) {
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request', chgObj.sys_id);
cTask.query();
var rowCount = cTask.getRowCount();
var cCount = 0;
while (cTask.next()) {
if (cTask.active == false) {
cCount++;
}
}
var answer = false;
if (rowCount == cCount && rowCount > 0) {
answer = true;
}
return answer;
},
implementTasks: function(chgObj) {
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request', chgObj.sys_id);
cTask.addQuery('active', true);
cTask.query();
var rowCount = cTask.getRowCount();
var iCount = 0;
while (cTask.next()) {
if (cTask.state == 10) {
iCount++;
}
}
var answer = false;
if (rowCount == iCount && rowCount > 0) {
answer = true;
}
return answer;
},
3. Wait Workflow Activities:
- If you choose to use the methods from the Script Include, you can call them from the Wait Workflow Activity.
- For checking if all Change Tasks are in a state of Implement, use the following syntax:
var sInc = new ChangeUtils();
answer = sInc.implementTasks(current);
- It is unclear if your records are set to be inactive when set to be Implement.
- You may also want to have an additional wait that waits for all tasks to be closed.
- For checking if all Change Tasks are closed, use the following syntax:
var sInc = new ChangeUtils();
answer = sInc.closedTasks(current);
4. Set Values Workflow Activity:
- If the desire is to automatically set the state of the Change record after all related tasks are set to Implement, then you can do so with a Set Values Workflow Activity.
Hopefully this will give you enough of a sample to work with.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 08:13 AM
Your business rule cannot directly influence the browser and tell it to reload. A better solution would be to just watch the State field with an onChange client script, and use the client script to tell the page to reload if the new state is Implement.
As-is, this client script would reload the page when Implementation is chosen as the state, whether it was chosen by a user or business rule. I'm not sure how you can account for changes from the background (that your business rule made, and that the form synced automatically), versus changes that a person made by clicking a different State value, but this is close to what you want.
Your client script would look something like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// If the new value is "Implementation", reload the page.
if (newValue == "implementation"){ // Use the choice value here. I guessed at what the value would be.
location.reload(true); // true says to not use cache. This is optional.
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 08:27 AM
Unfortunately, Business rules run server-side and do not refresh the page as you wish they did. Another option would be to set up a wait condition in your workflow, then when those conditions are met (all open Change Tasks related to this Change are set to Implement), then change the state. If you choose to do this, you might want to have a Business rule that writes to the Change Request record after the Change task changes to be implement. I typically write to the Work notes indicating the Change Task has been set to Implement. The reason why we do this is the wait condition will only run on your workflow whenever the record the workflow is running on is modified. You probably have some logic in your current Business rule on the change_task table that checks to see if all other change_task records are set, you can use this logic in your Wait workflow activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 04:54 AM
Hello Patrick and Christopher,
Thank you for sharing your opinions with me!
So, let me ask you the following - after I cannot reload the page form via a Business Rule, then would it be a solution, to say so, if I modify the default Workflow for Normal Change: "Change Request - Normal" and add a 'Run Script' activity after the 'Set Value' activity which moves the Change Request to Scheduled state, just before the 'Wait for condition' activity and add the code of my Business Rule into it (the 'Run Script' activity)? Then I will disable my BR and use the code portion in the WF.
Do you believe once the WF uses my script - the page will be reload?
Here I have some doubts:
- I am not sure if I will not break the WF logic by adding 'Run Script' activity after the 'Set Value' one and before the 'Wait for condition' one -> in this direction: check out NOTE1 located below;
- I am also not sure if the script which I am using in my Business Rule will work at all, as the WF itself runs against Change Request (change_request) table, while I created my Business Rule so it can run against Change Task (change_task) table;
NOTE1: as this is a default Workflow (WF) in order to not break its logic, and if I will be doing this at all -> instead of modifying it (the WF) I will copy it, disable the OOB one, and then go to interceptors and point to the copied version of the WF, and then perform my changes into it;
What do you think about adding this (adding the code into a WF)?
@ Patrick, to be honest, if I will be scripting, I would prefer to use Business Rule instead of Client Script.
@ Christopher, would it be comfortable for you to provide me with more detailed explanation of your thought about the BR & WF?
Cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 08:21 AM
It was my understanding that a Change Manager would be manually setting the Tasks associated with the change to have the Implement State. This is why I proposed using the Wait condition within the workflow. It appears that once all of the related tasks are in Implementation State, the Change Request should then be in Implement state. If this is your business process, then we should be able to leverage a Business Rule and a Wait condition.
1. Business rule: Set Change when State is Implement
- Create an onAfter business rule that runs when the state changes to Implement
- This will 'touch' the Change record so that the Wait condition will re-check.
- I will use the state value of 10 in my example since I do not know what your Implement state is.
- Here is a sample code:
Condition: current.state.changesTo(10)
Script:
(function executeRule(current, previous /*null when async*/) {
var notesTxt = 'Change Task ' + current.number + ' set to: ' + curent.state.getDisplayValue();
var chgObj = new GlideRecord('change_request');
chgObj.get(current.change_request);
chgObj.work_notes = notesTxt;
chgObj.update();
})(current, previous);
2. Script Include: ChangeUtils
- As of Geneva, there is an existing Script Include that can be used with Change Request: ChangeUtils
- Adding additional methods to this Script Include will allow you to call it from within any workflow.
- Having your script outside of the workflow allows you to edit the function without having to check out the workflow.
- Below are two methods you can add to this Script Include:
closedTasks: function(chgObj) {
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request', chgObj.sys_id);
cTask.query();
var rowCount = cTask.getRowCount();
var cCount = 0;
while (cTask.next()) {
if (cTask.active == false) {
cCount++;
}
}
var answer = false;
if (rowCount == cCount && rowCount > 0) {
answer = true;
}
return answer;
},
implementTasks: function(chgObj) {
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request', chgObj.sys_id);
cTask.addQuery('active', true);
cTask.query();
var rowCount = cTask.getRowCount();
var iCount = 0;
while (cTask.next()) {
if (cTask.state == 10) {
iCount++;
}
}
var answer = false;
if (rowCount == iCount && rowCount > 0) {
answer = true;
}
return answer;
},
3. Wait Workflow Activities:
- If you choose to use the methods from the Script Include, you can call them from the Wait Workflow Activity.
- For checking if all Change Tasks are in a state of Implement, use the following syntax:
var sInc = new ChangeUtils();
answer = sInc.implementTasks(current);
- It is unclear if your records are set to be inactive when set to be Implement.
- You may also want to have an additional wait that waits for all tasks to be closed.
- For checking if all Change Tasks are closed, use the following syntax:
var sInc = new ChangeUtils();
answer = sInc.closedTasks(current);
4. Set Values Workflow Activity:
- If the desire is to automatically set the state of the Change record after all related tasks are set to Implement, then you can do so with a Set Values Workflow Activity.
Hopefully this will give you enough of a sample to work with.