Update Demand state when Enhancement is Closed Complete

WaledBajukhaif
Tera Expert

We create Demand [dmn_demand] record, then create enhancement [rm_enhancement] record from the demand record. the demand state changes to Approved once enhancement is created.

My request is when we close enhancement record, update the demand state to Complete.

 

Any help/thoughts is be appreciated!

 

Regards

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

The flow should look like this:

MarkManders_0-1711611011611.png

MarkManders_1-1711611044493.png

MarkManders_2-1711611074704.png

MarkManders_3-1711611102666.png

MarkManders_4-1711611121956.png

 

And if you insist on using a BR, why not make it simple? Trigger it after update of the enhancement with state = closed and use this:

 

var demand = new GlideRecord('dmn_demand');
demand.addQuery('enhancement',current.getUniqueValue());
demand.addActiveQuery();
demand.query();
while(demand.next()){
	demand.setValue('state', 9); // completed
	demand.update();
}

 

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

12 REPLIES 12

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @WaledBajukhaif 

 

You need to create the BR after insert.

 

Here is baseline code for Inc and task:

 

https://www.servicenow.com/community/incident-management-forum/i-want-to-close-incident-task-when-in...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Thanks AG,

I followed the link but did not work. i think i missed something in my script can you take a look a it. see attached.

 

i created after update BR on Enhancement table with condition: state changes to closed complete.

script:

(function executeRule(current, previous /*null when async*/) {
   
    // Add your code here
    var demState = new GlideRecord ('dmn_demand');
demState.addQuery('rm_enhancement', current.sys_id);
demState.addEncodedQuery('state!=9'); //will check if it's not closed
demState.query();

while(demState.next()) {
demState.state = 3;
demState.update();
}
   
})(current, previous);

Hi @WaledBajukhaif 

 

I am not a coder 😞 , so cant help much.

 

@Mark Manders  what you say. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Unsure why you want to go for a BR, when it's so easy to just drag and drop in a flow, but since it looks like you are set on the BR: try running it before instead of after, or change the condition to 'is completed' when you want to run it after.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark