Sharing Comments between Request, Request Items, and Catalog Tasks

Brian Treichel
Tera Guru

Hello, We are trying to share all of the comments between all of the Request, Request Items, and Catalog Tasks, but keep running into issues. Here are the circumstances we are trying to cover:

Comment Added to Request: Add Comment to all RITMs and TASKs

Comment Added to RITM: Add Comment to REQ and all of the TASKs for the RITM

Comment Added to TASK: Add comment to the REQ and the TASK's RITM

We have created 3 Business Rules for each of these circumstances, however, they are triggering each other.

The first thing I tried doing was adding setWorkflow(false) to all of the GlideRecord updates, but this looks like it's hindering the submission of the comment into the activity log. Basically, it looks like the comments are being committed at all.

Here is a simple example of just the RITM and REQ comment sharing:

Table: Request

When: After - Insert or Update

Filter: Additional Comments changes

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('request',current.getUniqueValue());

ritm.query();

while(ritm.next()){

  ritm.comments = 'Comment added on Request: ' + current.comments;

  ritm.setWorkflow(false);

  ritm.update();

}

Table: Request Item

When: After - Insert or Update

Filter: Additional Comments changes

var req = new GlideRecord('sc_request');

if(req.get(current.request.sys_id)){

  req.comments = 'Comment added on Request Item: ' + current.comments;

  req.setWorkflow(false);

  req.update();

}

Thanks!

5 REPLIES 5

kristenankeny
Tera Guru

Hi Brian - We handle this by appending "update from [record type]" to the comment when we add it to the current record and then, prior to adding the comment, make sure the one it's trying to add didn't originate from the current record type. Alternately, you could add the record number to the beginning. This is what our script looks like on approvals attached to requested items:



        str = current.comments;


  var pos = str.search('Update from Requested Item');


  if(pos == -1){


  gs.info('The push from Approval to RITM will trigger now: ' + current.comments);


  var gr = new GlideRecord('sc_req_item');


  gr.get(current.sysapproval);


  gr.work_notes = 'Update from Approval: ' + current.comments;


  gr.update();


  }


  else{


  gs.info('I will not push this comment from Approval to RITM: ' + current.comments);


  }


This is so simple yet genius. Why this isn't "out of the box" 4 years later is beyond me, but thank you!

BALAJI40
Mega Sage

Basically, the problem is with the below line.


  1.   ritm.setWorkflow(false);  

If you remove the above line, it will update in activity log.



It is because, to update the comments in activity fields might be run some backed condition through some business rules, which are hidden, But you are not running any business rules it will not added to activity log.


also add the below condition,


current.work_notes.getJournalEntry(-1



  1. var ritm = new GlideRecord('sc_req_item');  
  2. ritm.addQuery('request',current.getUniqueValue());  
  3. ritm.query();  
  4.  
  5. while(ritm.next()){  
  6.   ritm.comments = 'Comment added on Request: ' + current.comments.getJournalEntry(1); // if you give 1 it will give latest and if you give -1 it will fetch all the comments on the form
  7.   ritm.update();  
  8. }  

SanjivMeher
Kilo Patron
Kilo Patron

Hi Brian,



In the Request Business Rule add condition , current.comments.indexOf('Comment added on Request Item')==-1


In the Request Business Rule add condition, current.comments.indexOf('Comment added on Request')==-1



Please mark this response as correct or helpful if it assisted you with your question.