How to capture in worknotes when the sctask field changes.

Siva P
Tera Expert

Hi All,

I need to capture the field changes in worknotes sctask form. I have two fields 

1.Estimation hours 

2.Week and date 

These two fields applicable only for this task .when the user updates any changes on these fields previous values should capture in worknotes only for this sctask only...how I can achieve this..any help please suggest me.

 

Thanks all...

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Since you need only for 1 tasks out of many for the RITM

You need some unique field value such as short description to identify that particular task

BR: Before Update

Condition: Field 1 or Field 2 changes && current.short_description == 'Task 1'

Sample Script below

var str = '';

if(current.<field1> != '')

str = str + previous.<field1> + ' ';

if(current.<field2> != '')

str = str + previous.<field2>;

current.work_notes = str;

It would look like if field 1 is having hello and field 2 is having abc

hello abc

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure business rule and capture previous values

 

https://docs.servicenow.com/bundle/orlando-application-development/page/script/business-rules/concep...

 

Regards,

Sachin

Priyanka Chandr
Mega Guru

Hi,

Use after business rule on sc_task table

(function executeRule(current, previous /*null when async*/) {
	
	// Add your code here
	var set = new GlideappVariablePoolQuestionSet();
	set.setRequestID(current.getValue('request_item'));
	var workNote = "";
	set.load();
	var vs = set.getFlatQuestions();
	gs.log ('Size: ' + vs.size());
	for (var i=0; i < vs.size(); i++) { 
		if(vs.get(i).getDisplayValue() != '') { // Only get variables that were filled out
			workNote = workNote + vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n";
		}
	}
	current.work_notes = workNote;
	current.update();
	
})(current, previous);

Please mark it correct and helpful.

Thanks,

Tanushree Doiph
Mega Guru

Hi,

I want to add something in previous post,

 

Write a before BR on update checked

Condition.

Estimation hours changes

 

Code:

 

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

current.work_notes = previous.(field_name of Estimation hours).getDisplayValue();

})(current, previous);

 

Please mark correct and helpful.

Thanks 

Tanushree

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Since you need only for 1 tasks out of many for the RITM

You need some unique field value such as short description to identify that particular task

BR: Before Update

Condition: Field 1 or Field 2 changes && current.short_description == 'Task 1'

Sample Script below

var str = '';

if(current.<field1> != '')

str = str + previous.<field1> + ' ';

if(current.<field2> != '')

str = str + previous.<field2>;

current.work_notes = str;

It would look like if field 1 is having hello and field 2 is having abc

hello abc

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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