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

I tried to test this in my PDI which is on Vancouver, and the attachments did not copy.

I checked the property and the incident table was in there.

 

Has anyone else seen this in Vancouver?

 

Thanks,

Shannon

Hey,
That system property doesn't actually do anything. I had a ServiceNow support call and mentioned that the system property doesn't work.
The UI 'create incident' ui action has the code to copy attachments.
Some instances have an older version of the UI action owned by legacy ITSM workspace app, so it doesn't get updated.
The code should look like this:

var canCreateIncident = false;
if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
	canCreateIncident = current.update();
else
	canCreateIncident = true;

if (canCreateIncident) {
	var inc = new GlideRecord("incident");
	inc.initialize();
	inc.caller_id = current.opened_for;
	inc.short_description = current.short_description;
	if (gs.getProperty("com.snc.incident.create_from_interaction.save") === 'true') {
		inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number);
		var incSysId = inc.insert();
		if (incSysId) {
			var interactionRelatedGR = new GlideRecord("interaction_related_record");
			interactionRelatedGR.initialize();
			interactionRelatedGR.interaction = current.sys_id;
			interactionRelatedGR.document_table = 'incident';
			interactionRelatedGR.document_id = incSysId;
			interactionRelatedGR.insert();
		}
	}
	action.openGlideRecord(inc);
	new InteractionRelationshipUtil().copyAttachments(current, inc);
}

The last line is what you need
new InteractionRelationshipUtil().copyAttachments(current, inc); 


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

OK thanks, I'll try that.

Chaitanya Maddu
Tera Contributor

I tried below and it worked for me.. we can add inc.insert() before copying attachments,worknotes and additional comments in UI action script itself.

if(current.update()){
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.opened_for;
inc.short_description = current.short_description;

---New lines, need to insert record once needed fields are copied and then work on work notes and file attachments----
//record inserted to incident table
inc.insert();
//copying worknotes and additional comments from IMS to INC
inc.work_notes = current.work_notes.getJournalEntry(-1);
inc.comments = current.u_additional_comment.getJournalEntry(-1);
//copying attachments from IMS to INC
GlideSysAttachment.copy('interaction', current.sys_id, 'incident', inc.sys_id);


inc.update();
action.openGlideRecord(inc);
current.state = 'closed_complete';
current.active == false;
current.update();

}

Don't do this. It will cause issues with the task not showing up in the Related Task related list.

See KB0852997