- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 03:58 PM
I have requirement to look for and ensure ALL grc_remediation items have been approved using a custom field (u_state). The value of the u_state needs to be '2' in order for the grc_observation workflow to move to the next part of the workflow.
Here is the Wait for Condition in the workflow that does not appear to be working:
<NO CONDITIONS>
<script>
//Query for all grc_remediation items to check if all are approved.
var rec = new GlideRecord('grc_remediation');
rec.addQuery('source', current.sys_id);
rec.addQuery('u_state', '2');
rec.query();
if(rec.hasNext()){//if all grc_remediation items match the query
//Continue on since all MAPs are approved.
answer = true;
//current.approval = 'approved';
//For troubleshooting purposes
var latestState = rec.u_state.getGlideObject();
gs.addInfoMessage("This is the true state: " + latestState);
}
else{
//Continue waiting since all MAPs are not approved.
answer = false;
//For troubleshooting purposes
var latestState = rec.u_state.getGlideObject();
gs.addInfoMessage("This is the false state: " + latestState);
}
What am I doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 08:00 AM
Finally figured it out and tested it many, many times. Here is what I was missing: What to do when there are no records found, at first. So, I had to create another Wait for Condition before the one you solved for me:
FIRST Wait for Condition Name: Create at Least One Record
//First, navigate to the MAP table
var gr_tsk = new GlideRecord("grc_remediation");
//Lookup only those MAPs associated with this issue
gr_tsk.addQuery('source', current.sys_id);
//Query the MAP table
gr_tsk.query();
//Iterate through the records...
if (gr_tsk.next()) {
//If there is at least one record found, then proceed forward to the next Wait for activity...
answer = true;
} else {
//If there are no records found then exit the wait for activity...
answer = false;
}
Then, here is the next Wait for Condition, based on what you (Ajit) and Joe spoke into. I realized there was one other state I need to search for, which was #4, our Closed state.
SECOND Wait for Condition Name: Remaining Record Submissions and Approvals
//First, navigate to the MAP table
var gr_tsk = new GlideRecord("grc_remediation");
//Lookup only those MAPs associated with this issue
gr_tsk.addQuery('source', current.sys_id);
//Next, look for all states that are not 2 or 4
gr_tsk.addQuery('u_state', '!=', 2);
gr_tsk.addQuery('u_state', '!=', 4);
//Query the MAP table
gr_tsk.query();
//Iterate through the records...
if (gr_tsk.next()) {
//If there is at least one record found with a state that is not 2 or 4, continue waiting...
answer = false;
} else {
//If there's no records found then exit the wait for activity...
answer = true;
}
Then, I created Joe McCarty's provided Business Rule in grc_remediation table that is performed AFTER with Update checked:
CONDITION: current.wf_activity.isNil() && current.active.changesTo(false)
Script:
function onAfter(current, previous) {
forceReqItemUpdate();
function forceReqItemUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("grc_remediation");
if (ri.get(current.number)) {
wf.runFlows(ri, 'update');
}
}
}
All is now right in the world (or at least mine).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 08:00 AM
Finally figured it out and tested it many, many times. Here is what I was missing: What to do when there are no records found, at first. So, I had to create another Wait for Condition before the one you solved for me:
FIRST Wait for Condition Name: Create at Least One Record
//First, navigate to the MAP table
var gr_tsk = new GlideRecord("grc_remediation");
//Lookup only those MAPs associated with this issue
gr_tsk.addQuery('source', current.sys_id);
//Query the MAP table
gr_tsk.query();
//Iterate through the records...
if (gr_tsk.next()) {
//If there is at least one record found, then proceed forward to the next Wait for activity...
answer = true;
} else {
//If there are no records found then exit the wait for activity...
answer = false;
}
Then, here is the next Wait for Condition, based on what you (Ajit) and Joe spoke into. I realized there was one other state I need to search for, which was #4, our Closed state.
SECOND Wait for Condition Name: Remaining Record Submissions and Approvals
//First, navigate to the MAP table
var gr_tsk = new GlideRecord("grc_remediation");
//Lookup only those MAPs associated with this issue
gr_tsk.addQuery('source', current.sys_id);
//Next, look for all states that are not 2 or 4
gr_tsk.addQuery('u_state', '!=', 2);
gr_tsk.addQuery('u_state', '!=', 4);
//Query the MAP table
gr_tsk.query();
//Iterate through the records...
if (gr_tsk.next()) {
//If there is at least one record found with a state that is not 2 or 4, continue waiting...
answer = false;
} else {
//If there's no records found then exit the wait for activity...
answer = true;
}
Then, I created Joe McCarty's provided Business Rule in grc_remediation table that is performed AFTER with Update checked:
CONDITION: current.wf_activity.isNil() && current.active.changesTo(false)
Script:
function onAfter(current, previous) {
forceReqItemUpdate();
function forceReqItemUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("grc_remediation");
if (ri.get(current.number)) {
wf.runFlows(ri, 'update');
}
}
}
All is now right in the world (or at least mine).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 04:21 PM
Rhett,
in your case, hasNext() returns true if atleast one record is in state 2. it does not consider all the records which are not in state 2. your script should be like.
- var rec = new GlideRecord('grc_remediation');
- rec.addQuery('source', current.sys_id);
- rec.addQuery('u_state', '!=', '2');
- rec.query();
- if(rec.hasNext()){//if all grc_remediation items match the query
- //Continue on since all MAPs are approved.
- answer = false;
- //current.approval = 'approved';
- //For troubleshooting purposes
- var latestState = rec.u_state.getGlideObject();
- gs.addInfoMessage("This is the true state: " + latestState);
- }
- else{
- //Continue waiting since all MAPs are not approved.
- answer = true;
- //For troubleshooting purposes
- var latestState = rec.u_state.getGlideObject();
- gs.addInfoMessage("This is the false state: " + latestState);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 11:57 AM
I had a similar requirement with Change Request and change tasks. i had to wait for all change tasks to be closed completed to close the change. i used the wait activity on the workflow of change request to check if all change task of that change request are closed. I think the wait will work if the parent table of the tables referred in workflows is same. ex- Task table is parent table of Change request and change task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 12:00 PM
Thank you Ajit and you read my mind. I have been troubleshooting and for some reason your recommendation always takes me to the evaluation of true or the else statement. Still trying different combinations and looking at if my sys_id is correct between grc_observation to grc_remediation tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 12:12 PM
yeah, you were looking for records with state 2. i thought it would be better to look at records which are not in state 2. i dont have GRC to confirm the sys_id thing but if my code does not work you should try what Joe recommends. that should definitely work. hope you get this to work.