Copy comments and work notes from REQ to RITM

jtorres
Kilo Contributor

Hi Team,

I have an implementation in which we disabled the shopping cart from the service catalog, therefore, for each REQ we have only one RITM, we now have a requirement to copy all the comments and work notes from the request to its related RITM and the related Catalog tasks, in order to improve the interaction between end users who interact in the REQ and fulfiller users who interact in the RITM. Has any of you guys worked in something like this?

Any help would be greatly appreciated.

Thank you.

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


i assume that you want to copy the comments from REQ to RITM and then RITM to SCTASK as soon as comments are inserted on REQ.

 

IF so then use after update BR on REQ and condition will be comments change

See below:

Condition : current.comments.changes() || current.work_notes.changes()

Script:

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

// Add your code here
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next()){
gr.comments = current.comments;
gr.work_notes = current.work_notes;
gr.update();

var tsk = new GlideRecord('sc_task');
tsk.addQuery('request_item',gr.sys_id);
tsk.query();
while(tsk.next()){
tsk.comments = current.comments;
tsk.work_notes = current.work_notes;
tsk.update();
}
}
})(current, previous);

 

Thanks,
Ashutosh Munot

View solution in original post

23 REPLIES 23

johansec
Tera Guru

Is this just for historic data? or will people still comment on a req and you need it to trickle down there too?

For historic da

// Get each comment/worknote record on each request
var comments = new GlideRecord('sys_journal_field');
comments.addQuery('name', 'sc_request');
var qc = comments.addQuery('element', 'comments');
qc.addOrCondition('element','work_notes');
comments.query();
while (comments.next()) {
    // Get each child ritm
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('parent', comments.element_id);
    ritm.query();
    while (ritm.next()) {
        //Generate a new journal entry for that item ( comment or worknote)
        var newComment = new GlideRecord('sys_journal_field');
        newComment.initialize();
        newComment.element_id = ritm.sys_id;
        newComment.name = 'sc_req_item';
        newComment.element = comments.element;
        newComment.value = comments.value;
        newComment.autoSysField(false); // so that the records don't have system updates
        newComment.setWorkflow(false); // so no business rules are run
        newComment.insert();
    }
}

ta I think something like this will work. I HAVE NOT TESTED THIS. This is just somewhere to start. 

This would be ran as a fix script or background script.

jtorres
Kilo Contributor

Hi Johansec Thank you very much for your help, yes we actually want to get any update to those fields on any record wether it is RITM or REQ to be replicated in the other.

What we have seen is that it depends much on the users, end users tend to comment on the REQ, and fulfillers in the RITM, we just want to have them both still able to communicate with one another without them having to change the record on which they usually interact.