How do I get SC_task comments to populate on the RITM?

Matt W
Giga Contributor

Hi All,

I've recently setup a business rule to transfer any additional comments from the RITM to the SC_Task activity which works great. This was something that I found on the community. I am now looking to transfer SC_task comments back to the RITM activity but cannot get it to work. This is what I have got so far

Before Business rule

Insert and update ticked

Condition - current.comments.changes()

Script -

(function executeRule(current, previous /*null when async*/) {
 // Add your code here
 var user = new GlideRecord ('sys_user');
 user.addQuery('user_name', current.sys_updated_by);
 user.query();
 if (user.next()){
  if (user.sys_id != current.request.requested_for){
   var gr = new GlideRecord('sc_req_item');
   gr.get(current.request_item);
   gr.comments = current.comments;
   gr.update();
  }
 }
 })(current, previous);

Any help would be greatly appreciated.

Thanks,

Matt

 

 

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

This question comes up quite frequently in the community. I recommend you do a search to see what others have done. It's pretty much the same solution every time.

In any case, you want to write an AFTER business rule on the sc_task table. Your user lookup is unnecessary since the person making the comments is the same as the person logged in, so you can add that to the condition. Note: this code has not been test.

 

Name: Copy comments

Table: Task (sc_task)

Insert: true

Update: true

Advanced: true

Condition: current.comment.changes() && gs.getUserID() != current.request.requested_for

Script:

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

    var ritmGr = new GlideRecord('sc_req_item');

    if (ritmGr.get(current.request_item)) {
        ritmGr.comments = current.comments.getJournalEntry(1);
        ritmGr.update();
    }

})(current, previous);

 

View solution in original post

3 REPLIES 3

Shashikant Yada
Tera Guru

You need to write OnAfter Business rule.

Chuck Tomasi
Tera Patron

This question comes up quite frequently in the community. I recommend you do a search to see what others have done. It's pretty much the same solution every time.

In any case, you want to write an AFTER business rule on the sc_task table. Your user lookup is unnecessary since the person making the comments is the same as the person logged in, so you can add that to the condition. Note: this code has not been test.

 

Name: Copy comments

Table: Task (sc_task)

Insert: true

Update: true

Advanced: true

Condition: current.comment.changes() && gs.getUserID() != current.request.requested_for

Script:

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

    var ritmGr = new GlideRecord('sc_req_item');

    if (ritmGr.get(current.request_item)) {
        ritmGr.comments = current.comments.getJournalEntry(1);
        ritmGr.update();
    }

})(current, previous);

 

Matt W
Giga Contributor

Thanks for the help much appreciated.