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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Do you mean "Task closure note" in front of the copied comment from the RITM?

In that case, you could do something like:

gr_task.comments = 'Task closure note\n\n' + current.comments.getJournalEntry(1);

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

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 Mark,

Thanks for the reply, that is correct i would like to add text as you have suggested, but slightly different requirement. So we have multiple sctask for an ritm > and when one of the task is closed the closure notes are cascaded to all the sctask of that ritm with the screenshot above, in this instance because each task will be with different teams/assigned to person > looking at this text on their task, they wont know why it is there > thus, what we want is to add text as "Another task closure note" so that they know that the closure note is from another task.

Putting this on your suggested line will also add that same comment to all task including the closed task activities too > so I am not sure  how to adjust this code on this requirement.

gr_task.comments = 'Another Task closure note:\n\n' + current.comments.getJournalEntry(1);

Hi there,

So the comment from one task should be copied to all other tasks? Though issue is, this is also set another time on the current task?

I just added one addQuery rule, to exclude the current record. Would this help?

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

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

	while(gr_task._next()) {
		gr_task.comments = 'Another Task closure note\n\n' + current.comments.getJournalEntry(1);
		gr_task.update();
	}

})(current, previous);

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

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,

This is a bit confusing. If I look at the title and your code, we are talking about the current RITM. 'request_item',current.sys_id suggests this is on the RITM.

While you are mentioning in the last comment - if I understand correctly - 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?

Should the update, the Business Rule, run on update of a sc_task instead of the RITM?

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