how to automatic set Yes/No field as no in sc_task table for 1 catalog item

keval3
Tera Contributor

Hi All,

I have below requirement...

 in the related list of sc_task table there are multiple yes/no field. I wanted to mark those field as NO when state is closed. but these is only for 1 catalog item not for global.  kindly let me know how to do it.

 

Thanks & Regards

KP

4 REPLIES 4

Juhi Poddar
Kilo Patron

Hello @keval3 

You can meet your requirement with the help of business rules.

Steps:

  1. Create a Business Rule on the sc_task table:

    • Trigger: Before update
    • Condition: Leave blank (we'll handle the condition in the script)
    • Advanced: Check the "Advanced" checkbox to add a script.
  2. Script:

 

// Check if the state is 3, 4, or 7(modify as per your requirement) and the catalog item matches the specific item
if ((current.state == 3 || current.state == 4 || current.state == 7) && 
    current.parent.cat_item == 'catalog_item_sys_id') { // Replace with your catalog item's sys_id
    
    // Set the Yes/No fields to "No"
    current.yes_no_field_1 = false; // Replace with your field names
    current.yes_no_field_2 = false;
    current.yes_no_field_3 = false;
    // Add more fields as needed
}

 

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

Ankur Bawiskar
Tera Patron
Tera Patron

@keval3 

you can have after update BR on sc_task

Condition: State Changes to [Close Complete] && current.request_item.cat_item.name == 'Your Catalog Item Name Here'

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var ritmRec = current.request_item.getRefRecord();
	ritmRec.variables.variable1 = 'No'; // give correct choice value and variable name here
	ritmRec.variables.variable2 = 'No'; // give correct choice value and variable name here
	ritmRec.update();

})(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

@keval3 

Hope you are doing good.

Did my reply answer your question?

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

Sarthak Kashyap
Tera Expert

Hi @keval3 ,

Please create After Update BR, and add below code 

if ((current.state == 3 || current.state == 4 || current.state == 7) && current.parent.cat_item == 'catalog_item_sys_id') {
    var currentRITM = current.request_item.getRefRecord();
    currentRITM.variable.variableName_1 = false; // Replace with your field names
    currentRITM.variable.variableName_2 = false;
    currentRITM.variable.variableName_3 = false;
}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak