How to transfer attached files from interaction to request or incident?

Joaquin Campos
Mega Sage

Dear community,

We're doing some preparation to transition from calls to interactions and currently we have one challenge: it's about transferring original attached files in interactions to new requests or incidents.

So far we can use the standard UI Action "Create Request" to link interactions with new requests and it works as expected and creates a link between current interaction and new request but in case attached files were included in the original interaction, those are not included in the new request.

I've done some research and seems that including in the script something like following line should work:

GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id');

But in my case, I'm missing the sys_id of the destination record. I'm not sure if that's my only issue but the point is that right now it's not working:

find_real_file.png

 

Would anyone have any advice to solve our issue? Same issue is applicable to "Create Incident" standard UI action.

 

Thank you in advance!

 

Joaquín

1 ACCEPTED SOLUTION

Joaquin Campos
Mega Sage

Hi all,

I've contacted ServiceNow about this and they've mentioned that it works as expected as it's not the intention of interactions to transfer attached files to related records. My opinion is that from a fulfiller point of view it's not nice having to go back to the original interaction in case you want to check any original attached file.

Having said this, finally I've managed to solve this by creating a business rule on interaction_related_record table after the insert. Here the code I've added:

 

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

// Add your code here
if (current.document_table == 'incident'){
var inc = new GlideRecord('incident');

inc.addQuery('sys_id',current.document_id);
inc.query();

if (inc.next()){
GlideSysAttachment.copy('interaction', current.interaction, 'incident', inc.sys_id);
}
}
else if (current.document_table == 'sc_request'){
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request',current.document_id);
ritm.query();

if (ritm.next()){
GlideSysAttachment.copy('interaction', current.interaction, 'sc_req_item', ritm.sys_id);
}
}
})(current, previous);

 

I've tested this and works as expected for both incidents and service requests from Agent Workspace.

Additionally there's already an idea in the idea portal asking for this functionality to ServiceNow.

The idea is called "Agent Workspace - copy attachments from Interaction to Incident". I hope everyone interested on this implementation can support it and subscribe to it to be up to date.

 

Hope it helps!

 

Joaquín

View solution in original post

14 REPLIES 14

Hi @Utsav JAISWAL,

 

The code was added to a business rule that whenever a new interaction related record was created, it was executed:

First thing that the code does is to check if we're transferring to an incident. If that's the case, then we check the incident records to find the one linked to our interaction and finally we attach the files to the incident:

if (current.document_table == 'incident'){//We check if new record is an incident
var inc = new GlideRecord('incident');

inc.addQuery('sys_id',current.document_id);//If that's the case then we do a query to the incidents table to find the record
inc.query();
if (inc.next()){
GlideSysAttachment.copy('interaction', current.interaction, 'incident', inc.sys_id);//And we attach the files from the interaction
}
}

 

There's another case if we're transferring to a service request. In that case we proceed the same way, by finding the right record and attaching the corresponding files:

 

else if (current.document_table == 'sc_request'){//In case it's not an incident, we check if it's a service request
var ritm = new GlideRecord('sc_req_item'); //If it's a service request we do a query to find the right record
ritm.addQuery('request',current.document_id);
ritm.query();
if (ritm.next()){
GlideSysAttachment.copy('interaction', current.interaction, 'sc_req_item', ritm.sys_id);//In case the record is found, then we attach the files from the interations
}
} 

 

Hope this helps!

 

Joaquín

 

 

Community Alums
Not applicable

Hii, thankyou @Joaquin Campos I understand the code now and it is working fine in my PDI. But I need to apply this functionality in my organisation (as in DEV instance) I have written the same code but it is not coming there..

Hi @Utsav JAISWAL ,

 

Maybe you have to activate interactions? Please refer to the following link:

 

https://docs.servicenow.com/bundle/utah-servicenow-platform/page/administer/interaction/task/activat...

 

Hope it helps!

 

Joaquín

Community Alums
Not applicable

Thankyou @Joaquin Campos I will surely try this..

Thanks & Regards
Utsav

There is now OOB functionality to do this. 
Be mindful that if you have customised or made custom functionality you may now see two attachments being copied.
The system property 'com.glide.interaction.attachments.copy' controls which tables are copied from the interaction.
That being said, there is a bug in Tokyo which causes this not to work.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022