State is not moving back until we refresh it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:15 AM - edited 02-09-2024 01:22 AM
Hello,
whenever we are trying to move the state then it will check if any open task records are there or not. if there are no-open tasks records then state will move to next state or else it will throw an error and remains on same state.
here Issue is when we are trying to move the state from "perform post test activities" to close and if any open tasks are present then it's throwing an error but state will be close and if we refresh the page then it will go back to "perform post test activities" state.
Here in the below code it's working fine for all states expect for close.
Could anyone please help me what is the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:20 AM
Hi @Venkat141
Even I am not developer, but still want to know. you are running BR before or after? Also OOTB you can check on change flow as well.
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:33 AM
Hello @Venkat141 ,
Please give a try to the script below and see how it works for you.
(function executeRule(current, previous /*null when async*/) {
// To check active tasks in each valid state
var checkTaskAgg = new GlideAggregate('x_nr_it_service_co_itscm_task');
checkTaskAgg.addQuery('parent', current.sys_id);
checkTaskAgg.addQuery('active', true);
checkTaskAgg.addAggregate("COUNT");
checkTaskAgg.query();
if (checkTaskAgg.next() && checkTaskAgg.getAggregate("COUNT") > 0) {
gs.addErrorMessage(gs.getMessage('Please close open tasks from the previous state to move to the next state'));
current.setAbortAction(true);
// The state should not be changed here
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:42 AM
Hi @Aniket Chavan ,
Still not working. Please find below snippet. its throwing an error and moves to close state but if we refresh the page state will go back to perform post test activities state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 11:46 PM
Hello @Venkat141 ,
I believe operation is setting only display value of state as closed but not backend value in data base operation as closed and that is the reason after refresh your value is resetting to current which you required.
Script optimization :
you don't have to set previous value to current one when you don't have to change the state and needs to throw error only.
Please remove all state transition code and keep only error code if active query ran successfully.
Second check : please check any client operation is working on your same condition for state field which setting the value as closed on form only.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Warm Regards,
Subhashis r7