How to sync attachment from the request on service now to jira

Originally asked by Yael on 03 November 2021 (original question)


I need to send attachment from service now to Jira but the files attach to the request and not to the catalog task.

I tried to use: replica.attachments = catalogTask.attachments, but it sync files that attach to the catalog task.

How can I sync it?


Answer by Andres Martynowicz on 22 February 2022

Hi Yael ,

I have been able to reproduce your issue.

Please try the following:

Incoming SNOW instance:

if(entity.tableName == "incident") {
    replica.key            = entity.key
    replica.summary        = entity.short_description
    replica.description    = entity.description
    replica.attachments    = entity.attachments
    replica.comments       = entity.comments
    replica.state          = entity.state
    
    /*
    Use a field"s internal name to send its value
    Example: Resolution Notes -> resolution_notes
    This works for all other entity types as well
    
    replica.resolution_notes = entity.resolution_notes
    */
}
//any other entity can be synced using the table name and the entity variable
else if(entity.tableName == "cmdb_ci_business_app") {
    replica.key            = entity.key
    replica.summary        = entity.short_description
    replica.description    = entity.description
    replica.name           = entity.name
}
else if(entity.tableName == "sc_task") {
    replica.key            = entity.key
    replica.summary        = entity.short_description
    replica.description    = entity.description
    if (entity.request_item) {
        def await = { f -> scala.concurrent.Await$.MODULE$.result(f, scala.concurrent.duration.Duration$.MODULE$.Inf()) }
        
        def orNull = { opt -> opt.isDefined() ? opt.get() : null }
        
        def ritmId = entity.request_item.link.split("/").last()
        
        def attachments = nodeHelper.snowClient.getAttachmentsMetadata(ritmId)
        
        def sequenceOfAttachments = await(attachments)
        
        def listOfAttachmentsResults = scala.collection.JavaConverters.seqAsJavaList(sequenceOfAttachments)
        
        def listOfHubAttachments = listOfAttachmentsResults.collect({
            attachmentResult ->
            def a = new com.exalate.basic.domain.hubobject.v1.BasicHubAttachment()
            a.filesize = attachmentResult.size_bytes as long
            a.id = attachmentResult.sys_id as String
            a.filename = attachmentResult.file_name as String
            a.mimetype = attachmentResult.content_type as String   
            a

        })
        
        replica.attachments = listOfHubAttachments
    }
}

Comments:

Yael commented on 28 February 2022

Hi,

It’s work.

Thanks a lot (old community) (old community)

Answer by Andres Martynowicz on 17 February 2022

Hi Yael ,

I have been able to set up the scenario and I am still working in order to reproduce the issue.

I will provide an update as soon as I can Exalate the attachments or next Friday (24th February).


Answer by Andres Martynowicz on 14 February 2022

Hi Yael,

I am still working on this issue and try to update this thread by the end of the week.

Kind regards,

Andres


Answer by Ariel Aguilar on 05 November 2021

Have you tried:

replica.attachments    = issue.attachments

Kind regards,

Ariel