Add count in string field whenever comments are added in incident

Vijay Baokar
Kilo Sage

Hello Folks,

 

I have a string field where count needs to be increased by 1 whenever caller updates the comments. This is needed for reporting to capture communication count from caller.

2 ACCEPTED SOLUTIONS

OlaN
Giga Sage
Giga Sage

Hi,

I would suggest you write an onBefore Business rule to handle this.

 

Business rule should run only on update.

 

Conditions would be:

additional comment changes

AND

updated by is same as caller.user ID

 

Script something like below:

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

	var counter = current.getValue('u_your_custom_field_name');
	if (!counter){
		current.setValue('u_your_custom_field_name', '1');
	}
	else{
		counter = parseInt(counter, 10);
		counter++;
		current.setValue('u_your_custom_field_name', counter);
	}

})(current, previous);

 

Try it, and see if it works.

View solution in original post

Oh, sorry about that, change the last line like the following:

 

current.setValue('u_your_custom_field_name', counter.toString());

View solution in original post

4 REPLIES 4

OlaN
Giga Sage
Giga Sage

Hi,

I would suggest you write an onBefore Business rule to handle this.

 

Business rule should run only on update.

 

Conditions would be:

additional comment changes

AND

updated by is same as caller.user ID

 

Script something like below:

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

	var counter = current.getValue('u_your_custom_field_name');
	if (!counter){
		current.setValue('u_your_custom_field_name', '1');
	}
	else{
		counter = parseInt(counter, 10);
		counter++;
		current.setValue('u_your_custom_field_name', counter);
	}

})(current, previous);

 

Try it, and see if it works.

I am getting results as 1.0, 2.0, 3.0 but i need like 1 for first comment , 2 for second comment.

Oh, sorry about that, change the last line like the following:

 

current.setValue('u_your_custom_field_name', counter.toString());

Thanks Olan, have a great day.