The CreatorCon Call for Content is officially open! Get started here.

Copy comments and work notes from REQ to SCTASK and SCTASK to REQ?

Community Alums
Not applicable

Hi All,

I am currently configuring our Service Catalogue.  For each REQ there will be 1 RITM and 1 SCTASK.

The end user will use the REQ via the portal to receive updates/add comments.

The fulfiller will use the SCTASK to complete the task/view and update comments to the end user.

Can it be set so any comments added to the REQ will also be added to the SCTASK and any updates on the SCTASK will be added back to the REQ?

Thanks,
Alex

10 REPLIES 10

Since you're not updating the RITM, change your first rule to run on the sc_request table, then copy/paste both of your scripts here, and I'll take a look at them.

Community Alums
Not applicable

Hi Brad,

Thanks for your help on this.

1. Business Rule - Copy Comments REQ (sc_request) on sc_request table -

find_real_file.png

 

Script:

(function executeRule(current, previous /*null when async*/) {
	var sctask = new GlideRecord('sc_task');
	sctask.addQuery('request_item', current.sys_id);
	sctask.addQuery('active', 'true');
	sctask.query();
	while(sctask.next()){
		var curWN = current.work_notes.getJournalEntry(1);
		var curTN = current.number;
		var curAG = current.assignment_group.name;
		var curAC = current.comments.getJournalEntry(1);
		if(sctask.work_notes.getJournalEntry(1) == '' || curWN.indexOf(sctask.work_notes.getJournalEntry(1)) <0){
			var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
			sctask.work_notes = newWN;
			var newAC = curTN + " - assigned to " + curAG + "\n\n" + curAC;
			sctask.comments = newAC;
			sctask.update();
		}
	}
		
})(current, previous);

 

1. Business Rule - Copy Comments REQ (sc_task) on sc_task table -

 

find_real_file.png

 

Script:

 

(function executeRule(current, previous /*null when async*/) {
	var ritm = new GlideRecord('sc_req_item');
	if(ritm.get(current.request_item.sys_id)){  
		var curWN = current.work_notes.getJournalEntry(1);
		var curTN = current.number;
		var curAG = current.assignment_group.name;
		var curAC = current.comments.getJournalEntry(1);
		if(ritm.work_notes.getJournalEntry(1) == '' || curWN.indexOf(ritm.work_notes.getJournalEntry(1)) <0){
			var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
			ritm.work_notes = newWN;
			var newAC = curTN + " - assigned to " + curAG + "\n\n" + curAC;
			ritm.comments = newAC;
			ritm.update();
		}
	}
})(current, previous);

 

Thanks,
Alex

Here are the scripts adjusted for your REQ to SCTASK and vice-versa scenario.  The main change is that tasks are related to the req only via the ritm, but you can dot-walk that relationship both ways.

On sc_request table

(function executeRule(current, previous /*null when async*/) {
	var sctask = new GlideRecord('sc_task');
	sctask.addQuery('request_item.request', current.sys_id);
	sctask.addQuery('active', 'true');
	sctask.query();
	while(sctask.next()){
		var curWN = current.work_notes.getJournalEntry(1);
		var curTN = current.number;
		var curAG = current.assignment_group.name;
		var curAC = current.comments.getJournalEntry(1);
		if(sctask.work_notes.getJournalEntry(1) == '' || curWN.indexOf(sctask.work_notes.getJournalEntry(1)) <0){
			var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
			sctask.work_notes = newWN;
			var newAC = curTN + " - assigned to " + curAG + "\n\n" + curAC;
			sctask.comments = newAC;
			sctask.update();
		}
	}
		
})(current, previous);

and the sc_task table

(function executeRule(current, previous /*null when async*/) {
	var req = new GlideRecord('sc_request');
	if(req.get(current.request_item.request)){  
		var curWN = current.work_notes.getJournalEntry(1);
		var curTN = current.number;
		var curAG = current.assignment_group.name;
		var curAC = current.comments.getJournalEntry(1);
		if(req.work_notes.getJournalEntry(1) == '' || curWN.indexOf(req.work_notes.getJournalEntry(1)) <0){
			var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
			req.work_notes = newWN;
			var newAC = curTN + " - assigned to " + curAG + "\n\n" + curAC;
			req.comments = newAC;
			req.update();
		}
	}
})(current, previous);

Community Alums
Not applicable

Hi Brad,

Thanks again for this - I have copied the updated business rules.

The relationship between REQ to SCTASK and SCTASK to REQ seems to now be working.

However, it seems to be adding more comments than required, this is the view from the portal -

find_real_file.png

And -

find_real_file.png

 

On the REQ it looks like this -

 

find_real_file.png

Its adding Work Notes as well as additional comments?

Sorry to ask more questions!

Thanks,
Alex

 

I'm not exactly following - too many things going on at once I think.  Breakdown the steps for me - for each action you take, tell/show me the text you are adding, in which field, and the expected result vs the actual result.