Clear a variable in SC_task table and sc_req_item table when closing a SCTASK

Malin1
Tera Contributor

Hi,

We have a need to clear a variable value (social security number) in the sc_task table and the sc_req_item, when a SCTASK is completed and closed (Closed Complete, Closed Incomplete and Closed skipped). Reason is that we should not store social security number values in these tables in Servicenow.

 

The value needs to be cleared before the Request completed, Request Cancelled etc notification is sent out since we include variables in the notification. 

 

I assume that this could be done using a Business rule, but how should I write the script?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Malin1 

you can use before update BR on sc_task and have this script

Condition: current.request_item.cat_item.name == 'Your Item Name Here' && State [IS ONE OF] Closed Complete, Closed Incomplete, Closed skipped

Script:

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

	// Add your code here
	current.variables.variableName = '';

	var ritm = current.request_item.getRefRecord();
	ritm.variables.variableName = '';
	ritm.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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Malin1 

you can use before update BR on sc_task and have this script

Condition: current.request_item.cat_item.name == 'Your Item Name Here' && State [IS ONE OF] Closed Complete, Closed Incomplete, Closed skipped

Script:

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

	// Add your code here
	current.variables.variableName = '';

	var ritm = current.request_item.getRefRecord();
	ritm.variables.variableName = '';
	ritm.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

Malin1
Tera Contributor

Thank you Ankur your response were very helpful!