Copy transcript from the interaction to the Incident - Agent workspace/Agent chat

MR1
Tera Contributor

The below BR is working as expected but it's copying the transcription twice in the work notes of the incident.

 

We want copy the chat transcript from the interaction record to comments field of the related incident .

 

We have written an After BR on interaction table

Condition : Transcript is not empty

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

var inc = new GlideRecord('interaction_related_record');
inc.addQuery('interaction', current.sys_id);
inc.addQuery('document_table', 'incident');
inc.addQuery('type', 'task');
inc.query();
while (inc.next()) {

var incident = new GlideRecord('incident');
incident.addQuery('sys_id', inc.document_id);
incident.query();
while (incident.next()) {
incident.comments = current.transcript.toString();
incident.update();

}
}

})(current, previous);

1 ACCEPTED SOLUTION

Hi,

I believe you need to change the when to run condition.

AnilLande_0-1682561801307.png

 

It will make sure to run BR only when interaction is closed. At this moment your Business rule is running every time when the transcript changes.

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

10 REPLIES 10

Anil Lande
Kilo Patron

Hi,

Please try below:

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

var inc = new GlideRecord('interaction_related_record');
inc.addQuery('interaction', current.sys_id);
inc.addQuery('document_table', 'incident');
inc.addQuery('type', 'task');
inc.query();
if (inc.next()) {
var incident = new GlideRecord('incident');
incident.addQuery('sys_id', inc.document_id);
incident.query();
if(incident.next()) {
incident.comments = current.transcript.toString();
incident.update();

}
}

})(current, previous);
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

MR1
Tera Contributor

Unfortunately, it didn't help me yet

 

Hi,

Please make sure you have added proper condition on your BR so that it will not execute multiple times.

(function executeRule(current, previous /*null when async*/ ) {
gs.info('AAAAA - Running my BR');   // add logs to track your br Execution
var inc = new GlideRecord('interaction_related_record');
inc.addQuery('interaction', current.sys_id);
inc.addQuery('document_table', 'incident');
inc.addQuery('type', 'task');
inc.query();
if (inc.next()) {
var incident = new GlideRecord('incident');
incident.addQuery('sys_id', inc.document_id);
incident.query();
if(incident.next()) {
incident.comments = current.transcript.toString();
incident.update();

}
}

})(current, previous);

 

added log in BR, it should come only once.

you can put more logs to debug your script?

 

can you please help us understand what is your usecase? when exactly you want to update comments?

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

MR1
Tera Contributor

I tried with logs and it didn't help. In my case when Interaction is closed completed then I want to update the incident with interaction transcripts

Kindly find the conditions below

 

MR1_0-1682541404863.png

 

Thanks