Duplication of Additional Comments

AD7
Mega Contributor

Hi All,

I have written 2 Business Rules for copying comments from Case to Incident and from Incident to Case respectively. However, Comments get copied from Case to Incident but when i post a comment in Incident, same comment is displayed twice. 

Business Rules are as follows, along with the Duplicate Comment Screenshot.

Any help on this is higly appreciated.

From Case to Incident:

When to run: After Update

var latest = current.comments.getJournalEntry(1);
var notes = latest.substring(latest.indexOf(")")+1).split("/n/n");
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',current.parent);
gr.query();
gs.log('Before if','AD');
if(gr.next())
{
gr.comments = "Comments updated from "+current.number+"\n"+notes;
gr.update();
}

From Incident to Case:

When to run: After Update

var latest = current.comments.getJournalEntry(1);
var notes = latest.substring(latest.indexOf(")")+1).split("/n/n");
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id',current.u_case);
gr.query();

if(gr.next())
{
gr.comments = "Comments updated from "+current.number+"\n"+notes;
gr.update();
}

6 REPLIES 6

Naresh27
Tera Guru

Try adding this 2 lines below and see what happens in From Incident to Case, 

From Incident to Case:

When to run: After Update

var latest = current.comments.getJournalEntry(1);
var notes = latest.substring(latest.indexOf(")")+1).split("/n/n");
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id',current.u_case);
gr.query();

if(gr.next())
{

gr.autoSysFields(false);
gr.setWorkflow(false);


gr.comments = "Comments updated from "+current.number+"\n"+notes;
gr.update();
}

 

AD7
Mega Contributor

Hello Nari,

Thanks for the Reply!

I added those two lines in my Script. The Duplicate issue is resolved but now the comment is not getting copied to Case Ticket from Incident.

 

Vikram3
Giga Guru

Hi AD,

Try before update. It worked for me.

AD7
Mega Contributor

Hi Vikram,

Thanks for the Reply!

I tried with before update but still not working!