Copy Case Additional Comments into Incident

Sunil_th
Tera Contributor

Hi, I'm trying to copy additional comments from Case (Portal) into Incident and created before update business rule, this seems not to work. Can someone assist?

 

Sunil_th_0-1680569919360.png

 

 

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

if (!gs.nil(current.comments)) {
var grInc = new GlideRecord('incident');
if (grInc.get('sys_id', current.incident.sys_id)) {
grInc.comments = 'Work notes update on incident ' + current.number + ': ' + current.comments;
grInc.update();
}
}

})(current, previous);

 

Thanks,

SK

6 REPLIES 6

AnveshKumar M
Tera Sage
Tera Sage

Hi @Sunil_th ,

Try with below script.

 

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

 

if (!gs.nil(current.comments)) {

var grInc = new GlideRecord('incident');

if (grInc.get('parent', current.sys_id)) {

grInc.comments = 'Work notes update on incident ' + current.number + ': ' + current.comments;

grInc.update();

}

}

 

})(current, previous);

 

 

Thanks,

Anvesh

Thanks,
Anvesh

Hi @AnveshKumar M 

Thanks for the script, that didn't work. Is it some other condition in the business rule that's causing this?

 

Thanks,

Sunil

Hi @Sunil_th ,

Change the BR to After - Update and a condition like below, and use the script provided below.

 

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

    var inc = new GlideRecord('incident');
    inc.addQuery('parent', current.sys_id);
    inc.query();
    while (inc.next()) {
        var comment = current.comments.getJournalEntry(1);
        inc.comments = comment.trim();
        inc.update();
    }

})(current, previous);

 

AnveshKumarM_0-1680617606278.png

 

Thanks,

Anvesh

 

Thanks,
Anvesh

Hi @Sunil_th ,

Have you tried this script, let me know if it helped you to solve the issue.

 

Thanks,

Anvesh

Thanks,
Anvesh