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

Alex23
Kilo Guru

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

Brad Bowman
Kilo Patron
Kilo Patron

Hi Alex,

We are using 2 Business Rules to do something similar - on the sc_task and sc_req_item tables when work notes changes or comments changes.

This is the first BR running on the sc_task table.  You'll need something similar to get from sc_task to sc_req_item, then add sc_req_item to sc_request.  This has an extra check to make sure they don't keep updating each other recursively.

(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);

Then the similar script running in a BR on the sc_req_item table to update every one of its sc_task records.

(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);

Hi Brad,

Thank you so much for getting back to me!

Before I set these up and test, can you please confirm -

  • Should these both be set up as after and update?
  • Do I need to add 2 filter conditions to both - work notes and comments changes?
  • Is there any Condition I need to add?

Thanks again!
Alex

Sorry I forgot to specify.  Yes, we are running both after Update.  Since you want to update work notes and comments, and it's possible to change one without the other, then yes you'd want 2 Filter Conditions, separated by an OR.  No Condition.

Hi Brad,

I have been testing this but cannot get it to work 😞

I have 2 business rules set up,

  1. Copy Comments REQ (sc_req_item) on sc_req_item table
  2. Copy Comments REQ (sc_task) on sc_task table

Both like the below -

find_real_file.png

 

Any update on the REQ record, does not update the RITM or SCTASK.

When the end user updates the RITM, it does update the RITM and SCTASK but x2, both with a comment and a worknote -

find_real_file.png

 

I am definitely doing something wrong/missing something but cannot figure out what.

For my requirement, the REQ would be the only thing the end user needs to update to update the SCTASK and the fulfiller only needs to update the SCTASK to update the REQ.

Any further guidance would be much appreciated!

Thanks,
Alex