Business rule is not giving the desired result when change request state is closed from workflow

Akanksha35
Tera Contributor

I have a change request and it has child change request. When parent record is closed, child record should automatically be closed. The parent record is getting closed from workflow. I have created a BR on after update to set the state of child record to be closed when parent is closed. But the BR i have created is giving me the count as 0 which is incorrect. 

When the parent record is closed and I go the form and update the form and save the form then my BR is working perfectly fine and giving me the count as 1 .

 

var gt=new GlideRecord('change_request');
        gt.addQuery('parent',current.sys_id);
        gt.query();
        gs.log('count recorded  is '+gt.getRowCount());
 
Why it is not picking the correct count when parent record is closed from workflow. I have set the order of BR to 1100.
4 REPLIES 4

Namrata Ghorpad
Mega Sage
Mega Sage

Hi @Akanksha35 ,

Are you adding the current.update() in your workflow script to update the parent change request record.

Can you share the script that you tried in workflow.

And instead of creating business rule, you can create 1 more run script activity in your workflow and write the below script in that activity.

var gt=new GlideRecord('change_request');
gt.addQuery('parent',current.sys_id);
gt.query();
if(gt.next())
{
gt.state=choice value of state field for closed;
gt.update();
}

 

Please mark my answer as correct and helpful if it helps to resolve your issue.

Regards,

Namrata

Hi Namrata,

 

Thanks for replying.  I am not using current.update() in workflow.

I am using BR because i need to do this  requirement for all the types of change request so I have to make changes in all the workflows. That's why I am opting after BR to avoid making changes in all the workflows

Hi @Akanksha35 ,

Can you add current.update() in the script where you are changing the state of parent change request as closed and try once. And in the business rule add condition state is closed.

 

Regards,

Namrata

 

 

Hi Namrata,

 

I have used the condition 'state is closed' in my BR . The BR is executing. I have logs statement in line 1 , it is getting printed , then i added my logic.  Count is coming incorrect, when workflow sets the state to closed.

When i am opening a closed change request form and update anything to make my BR trigger, then count is coming correct.

 

(function executeRule(current, previous /*null when async*/) {
 gs.log("test BR frst if" + current.number);
         var gt=new GlideRecord('change_request');
        gt.addQuery('parent',current.sys_id);
        gt.query();
           gs.log('count recorded  is '+gt.getRowCount());