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

Joe Weisiger
Giga Expert

Pranav,

Yes this worked!! 

I really appreciate your help with this,

Joe

Vartul Agarwal1
Tera Contributor

@Pranav Bhagat 

Hi Pranav,

We have put in a similar solution and populating changed variables in the comments on our SCATSK. The issue we are facing here is with the variables which has special characters and line spaces in them. Even the variable value does not change, it is still printing that in the comments.

Below is example of the variable value:

TestABCD
/////
$$$$$
&&&&
%%%%%

And below is our script - 

(function executeRule(current, previous /*null when async*/ ) {
var str = '';
var key;
for (key in current.variables) {
var v = current.variables[key];
var p = previous.variables[key];
if (current.variables[key] != previous.variables[key] && previous.variables[key] != '') {
str += '\n' + v.getGlideObject().getQuestion().getLabel() + ' : ' + ' changed from ' + p.getDisplayValue() + ' to ' + v.getDisplayValue();
}
}
current.comments = str;
})(current, previous);