Copy comments from RITM to SCTASK

Sam198
Mega Guru

Hi all,

I have below BR to copy RITM comments to SCTASK, this comments get copied to all open and closed sctask with below, i would like to change/add text where it says "Task closure note" - how do i change my code?

find_real_file.png

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

// Add your code here
var gr_task = new GlideRecord('sc_task');
gr_task.addQuery('request_item',current.sys_id);
gr_task.query();
while(gr_task.next()){
gr_task.comments = current.comments.getJournalEntry(1);
gr_task.update();
}

})(current, previous);

 

 

1 ACCEPTED SOLUTION

Hi there,

If we go from a Business Rule which runs on a update on the sc_task, consider something like below. Tested and works.
You do have to tweak it a little bit! I don't like the before part, and I didn't set any condition on the Business Rule.

Kind regards,
Mark

find_real_file.png

find_real_file.png

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

	var grCatalogTask = new GlideRecord('sc_task');
	grCatalogTask.addQuery('parent', current.parent);
	grCatalogTask.addQuery('sys_id', '!=', current.getUniqueValue());
	grCatalogTask._query();

	while(grCatalogTask._next()) {
		grCatalogTask.work_notes.setJournalEntry('Copied comment from ' + current.number + ':' + '\n' + current.work_notes.getJournalEntry());
		grCatalogTask.update();
	}

})(current, previous);

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

10 REPLIES 10

Hi,

 

Yes this is correct
: " that you want to copy the last comment of a task, to all other tasks. Where the issue being, the comment is also copied to the task where this comment is from?" - This is the query.

Thanks in advance.

Hi there,

If we go from a Business Rule which runs on a update on the sc_task, consider something like below. Tested and works.
You do have to tweak it a little bit! I don't like the before part, and I didn't set any condition on the Business Rule.

Kind regards,
Mark

find_real_file.png

find_real_file.png

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

	var grCatalogTask = new GlideRecord('sc_task');
	grCatalogTask.addQuery('parent', current.parent);
	grCatalogTask.addQuery('sys_id', '!=', current.getUniqueValue());
	grCatalogTask._query();

	while(grCatalogTask._next()) {
		grCatalogTask.work_notes.setJournalEntry('Copied comment from ' + current.number + ':' + '\n' + current.work_notes.getJournalEntry());
		grCatalogTask.update();
	}

})(current, previous);

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi there,

Did this work for you? Or do we need to follow-up on this?

If my answer helped you in any way, please then mark it as helpful.

Please mark this answer as correct if it solves your problem. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi there,

Did this solve your issue? Or do we need to follow up on this?

Please mark this answer as correct if it solves your problem. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Sorry did not had chance to look at this one, been busy with some other stuff and other issues.

The above script seems to fit my requirements so i will mark that as correct.

 

Thanks again.