Business Rule, change task to update parent change record and advance change state

Jeff F
Kilo Contributor

I am a newbie and have hit a roadblock. We have a business requirement that when a active development change task is changed to a 'QA Review' state, loop through all active change tasks to verify they are all at 'QA Review' and if so, post parent change work notes stating the 'Change is ready for QA' as well as advance the Change state to QA Review.

So I added a business rule on the change_task table. It runs after insert or update when parent Change is at Implement state, change task is a development task type and task's state changes to QA Review.

First get the parent change and loop through all children tasks (this works)

//gets the changeID for this task
chg_task.addQuery('change_request',chg.sys_id);
chg_task.query();
//then loops through all associated change tasks
while (chg_task.next()){
//gets this task's state and type
taskState = chg_task.getValue('state');
taskType = chg_task.getValue('u_task_type');
//if task is dev then continue
if (taskType == 'dev'){
//if not closed complete, closed skipped or closed incomplete
if (taskState != 3 && taskState != 4 && taskState != 7 ){
//add
openDevTasks = openDevTasks +1;
//if at Ready for QA
if (taskState ==10){
//add
openDevTasksatQA = openDevTasksatQA +1;
}
}
}
}
//done processing all tasks
}

Now if all the active dev tasks equal all the active dev tasks at qa review, I get the parent change and try to update state as well as post work notes (this part doesn't work...BUT the three debug info msgs do load on the change form after the task is updated)

if (openDevTasks == openDevTasksatQA){
//all open dev tasks are at qa review. start on update to parent vvvvvvvvvvvvvvvvvvvvvvvvvvvv
//so show user msg
gs.addInfoMessage(' 1 - is debugging BR All Dev Tasks Ready for QA.');
var chgParent = new GlideRecord('change_request');
chgParent.addQuery('sys_id',chg.sys_id);
chgParent.query();
if (chgParent.next()){
gs.addInfoMessage(' 2 we have the change ID=' +chg.sys_id);
gs.addInfoMessage(' 3 we have the change number=' +chgParent.getValue('number'));
chgParent.state = 6;
chgParent.work_notes = "All open Development tasks are ready for QA Review. ";
chgParent.update();
}

}
//end updating parent change ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So any help in why the parent change is not being updated is appreciated.

I have tried adjusting the business rule order sequence, updating other parent fields and makes no difference. 

Thanks in Advance,

Jeff

4 REPLIES 4

dave_edgar
Mega Guru

I think you'll have to swap this to running async.

 

I'm sure i had a similar issue recently, don't have access to that code as swapped companies, but running a sync resolved.

 

Hope that helps you out

Hi, tried the async and that didn't resolve. 

Attached BR header and entire adv code for review.

Starting to think doing too much in one BR...?

Or how can I tell what other actions/processes run after BR completes?

Again, any advice, suggestions, are appreciated. thanks Jeff

Elijah Aromola
Mega Sage

The code you posted looks fine, I don't see any issues with it. If Daves comment above doesn't resolve your issue can you post a screenshot of your business rule? 

Jeff F
Kilo Contributor

Well in an attempt to get any insight on why parent change wasn't being updated, I adj the UI Policy on the form to allow state readonly=false. Then when I manually move change state from Implement to QA Review, I get this generic error 'Invalid update' msg (see screenshot). So being a newbie, is there any way to debug what other calls/actions/workflows, BR's etc are processing and specifically what is causing that error. ? thanks in advance - Jeff

find_real_file.png