Update work notes if variable changes

Joe Weisiger
Giga Expert

Hello,

I have an order guide/catalog item that uses a variable set and the variables are cascaded.  If someone changes a variable on an associated task I want to capture the change in the activity stream work note.  How can I accomplish this?

Thanks,

Joe

1 ACCEPTED SOLUTION

@Joe Weisiger 

 

Can you test this once 

var key;
	for(key in current.variables){
			if(current.variables[key] != previous.variables[key]){
				current.work_notes = "Variable changed "+key + "Value Changed to"+current.variables[key];
			}
	}

View solution in original post

16 REPLIES 16

Pranav Bhagat
Kilo Sage

Write a Business rule Which will check the values of variables

 

if(current.variables.variable1 != previous.variables.variable1){

current.work_notes ='field changed';

}

 

I haven't tested it but I think it will work

Regards

Pranav

Thank you for the reply Pranav!  

I created a new Business Rule on the sc_task table and put this script in the advanced tab.  There is an error on the script single quotes before field changed.

Hi,

Try this

Ensure this BR runs only for your catalog item so give your catalog item name here

BR: Before update on sc_task

Condition: current.variables.changes() && current.request_item.cat_item.name == 'Catalog Item Name here'

Script:

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

    // Add your code here

current.work_notes = 'Variable Changed';

})(current, previous);

Regards
Ankur

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

@Joe Weisiger 

Ensure you use valid business rule condition so that it works only for your catalog item.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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