- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:22 AM
@Ankur Bawiskar can you help me with below issue.
We need to close the long back created change tasks were state field is greyed out in draft state.already change request is in cancelled state. But still change task are in draft state. Tried background script to close those but still state is not getting changed. Can you please help me on this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:25 AM
your script is wrong
try this
var gr = new GlideRecord('change_task');
gr.addQuery('number', 'ctasknumber');
gr.query();
if (gr.next()) {
gr.state = 140;
gr.setWorkflow(false);
gr.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:26 AM
Hi @mohanmerava
Did you try via list view? Please share your script, what error you are getting.
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-18-2025 04:29 AM
Hello @mohanmerava
Ensure there are no business rules or workflows preventing the state change. Sometimes, these can enforce certain conditions that block updates.
When running a background script, you might need to disable workflows to prevent any business rules from interfering. Here's an example script you can try:
var gr = new GlideRecord('change_task');
gr.addQuery('number','CTASK0010001');//If you want to test for one CTASK use this line and if working fine latter comment it out.
gr.addQuery('state', 'draft'); // Adjust the query as needed
gr.addQuery('change_request.state', 'cancelled'); // Ensure the parent change request is cancelled
gr.query();
while (gr.next()) {
gr.setWorkflow(false); // Disable workflows
gr.state = 'closed'; // Set the desired state
gr.update();
}
Also, ensure that the state transition from draft to closed is valid according to your change task state model if its configured.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:45 AM
Hi viraj,
Tried above code but still state is in draft state. Is there any alternative as this task were created on 2016
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:30 AM
Hi Atul,
Tried from list view it is not getting updated.
Below script
var gr = new GlideRecord('change_task');
gr.addQuery('number', 'ctasknumber');
gr.query();
gr.state= 140;
r.update();