Before you submit your newly created incident, you may have added multiple attachments. But in some Service Integrations, it can only process one attachments at a time. In Service Integration meshlets, since Jackson’s XML parser does not work with repeated elements, it also can only process one attachment at a time.


Procedure

To start sending attachments individually, follow these steps:


Access Dynamic Share

In your ServiceNow instance, go to Perspectium > Replicator > Dynamic Share. Click the dynamic share you are using for your integration.

Then, set the Business Rule Order to before.

Set a Before Share Script

Add the following to the Before Share Script and replace the <tag_name> with the appropriate tag name and <dynamic_share_sys_id> with the dynamic share sys_id

if (psp_action == "insert") {
	var pspA = new PerspectiumAttachment();
	pspA.sendIndividualAttachments(current, "deferred", <tag_name>, <dynamic_share_sys_id>); 
}

(info) NOTE

  • If you update a record with multiple attachments, the first attachment will be inside the insert message while other attachments are in their separated messages.
  • Due to ServiceNow limitations, attaching multiple attachments on an insert will only send out one attachment.

Access Table Map

Access the table map for your integration by going to Perspectium Common Documents > PSP Common Table Maps.

In the related list towards the bottom of the form, search for the record with a target field set to attachments.

Then, replace <tag name> with the appropriate tag name. 

${TM:psp_attachment;table_sys_id=$[GR:sys_id];<tag name>;skip_insert;limit 1}

Access Transform Map

Access the transform map for your integration by going to Perspectium Common Documents > PSP Common Transform Maps.

In the Transform Script tab, look for the transform script starting with:

//onAfter for undeferring outbound messages, inactive by default 

Then, add the following script: 

 if (decodeData.indexOf("</attachments>") > -1) {
	outGR.name = outGR.name.replace("update", "attach");
 }

See the following example:

Create a new Script Action

(info) NOTE: Click here for the Perspectium Attachment script action XML. You can use the attached XML as a base, otherwise, follow the steps below. 

Go to System Policy > Events > Script Actions. Click New

In the Event name field, select attachment.uploaded. Check the Active box.

Then, input the following script in the Script field:

(info) NOTE Replace <tag name> with the appropriate tag name and <shared queue> to the target queue you are using in the dynamic share.

pspShareUploaded();
function pspShareUploaded() {
    var pspRepl = new PerspectiumReplicator();
    var pspUtil = new PerspectiumUtil();
 
    var tableName = event.parm1;
    var tableSysId = event.parm2;
 
    var tgr = new GlideRecord(tableName);
    tgr.addQuery('sys_id', tableSysId);
    tgr.queryNoDomain();
    if (!tgr.next()) {
        return;
    }
 
    var op = "attach";
 
    var qc = new GlideRecord('psp_replicate_conf');
    qc.addQuery('table_name', tableName);
    qc.addQuery('action_create', true);
    qc.addQuery('action_update', true);
    qc.addQuery('sync_direction', 'share');
    qc.addQuery('active', 'true');
    qc.addQuery('u_target_queue.u_name', '<shared queue>');
    qc.query();
    if(qc.next()) { 
 		// share record, setting tag to mark attachments
		if (tgr.operation() == "insert" || (tgr.isValidField("correlation_id") && tgr.correlation_id.nil())) {
			op = "deferred";
		}

		var agr = new GlideRecord(event.table);
		agr.addQuery("table_name", tableName);
		agr.addQuery("table_sys_id", tableSysId);
		agr.query();
		while (agr.next()) {
			if (!pspUtil.recordHasTag(agr, '<tag name>')) {
				pspRepl.shareOneRecord(tgr, qc, tableName, op, '<tag name>');
			}
		}
	}
}

Click Submit when you are done.