catalog client script to change sc_task state based on variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 02:38 PM
I have a catalog item that creates a catalog task. One of the variables on this catalog item is u_status. When that variable is changed to Complete and the record is saved, I would like the state to change to closed complete(3). I have tried an onSubmit and onLoad catalog client script, but cannot get it to work. How do I write this so it works?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 02:45 PM
Create a Business Rule on the Catalog Task table (sc_task) to update the state when u_status is set to "Complete":
Jenna just have table ->task, then advanced ->checked, when ->before, insert ->yes, update->yes,
In conditions ->"current.u_status.changesTo('Complete') && !current.operation() // Ensures it runs only when u_status changes to "Complete"
In script ->"current.state = 3; // Closed Complete"
save and activate the business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 03:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 05:28 PM
Hi @Jenna ,
Please share the code you have written for this change. Also, are you checking this "u_status" value somewhere in workflow/or/flow for task closure. You need to apply wait for condition.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2025 07:12 PM
you can use before update business rule on sc_task table
Condition:
current.request_item.cat_item.name == 'Your Item Name' && current.variables.u_status.changes()
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// give the correct value for complete
if(current.variables.u_status == 'complete'){
current.state = 3;
}
})(current, previous);
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