Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

catalog client script to change sc_task state based on variable

Jenna
Tera Expert

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?

6 REPLIES 6

MurtazaSaify
Tera Contributor

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

 

Murthy Ch
Giga Sage

Hi @Jenna 

You can do this in your flow. I don't think you can write new script.

 

Thanks,
Murthy

AshishKM
Kilo Patron
Kilo Patron

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Jenna 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader