Mapping internal/public attachments from SD to ZD

Originally asked by ben on 10 January 2022 (original question)


Hi,

i need a script that maps attachments made as internal/external in SD, to be internal/external, respectively, in ZD.

Please assist.

Thanks


Answer by Ariel Aguilar on 14 January 2022

Hi Ben,

Could you please give a try to the following:

if (executionInstanceName == "zd us") {
    replica.getClass().fields
    def locked = replica.getClass().declaredFields.find{it.name == "_locked"}
    locked.setAccessible(true)
    locked.set(replica, false)
    if(replica.addedComments.reverse().find()?.internal == true && !replica.addedAttachments.empty){
        replica.addedAttachments = replica.addedAttachments.collect{
            attachment ->
            def lockeda = attachment.getClass().declaredFields.find{it.name == "_locked"}
            lockeda.setAccessible(true)
            lockeda.set(attachment, false)
            attachment.internal = true;
            attachment
        }
    }
    issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
}

Thanks,

Ariel


Comments:

ben commented on 16 January 2022

Thanks, Ariel, that does the work but its still not a complete setup (old community)

so that files arent duplicated in the sync to ZD, the attachment mapping in the visual connection was turned off.

so no, files from ZD are not arriving on SD (the script takes from SD to ZD, but not from ZD to SD).

can you please advise a script to take attachments from ZD to SD (preferably such that its still respective of internal/external?

Ariel Aguilar commented on 17 January 2022

Hi Ben,

Yes with the visual mapping off, you may add the following to it to make look like this:

if (executionInstanceName == "zd us") {
    replica.getClass().fields
    def locked = replica.getClass().declaredFields.find{it.name == "_locked"}
    locked.setAccessible(true)
    locked.set(replica, false)
    if(replica.addedComments.reverse().find()?.internal == true && !replica.addedAttachments.empty){
        replica.addedAttachments = replica.addedAttachments.collect{
            attachment ->
            def lockeda = attachment.getClass().declaredFields.find{it.name == "_locked"}
            lockeda.setAccessible(true)
            lockeda.set(attachment, false)
            attachment.internal = true;
            attachment
        }
    }
    issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
}
if (executionInstanceName == "jira") {
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
}

With this configuration you may be able to even delete the mapping and both ways should work now. You may try this first and come back if the attachments are not going as expected from ZD to SD.

Kind regards,

Ariel

ben commented on 17 January 2022

hi ariel, the attachments arent going as they should. getting an error. please advise which information i should provide so you can look into it. thanks

ben commented on 17 January 2022

Hi Ariel, had a typo in the copy/paste of the script. its working as expected.

many thanks!!!

Ariel Aguilar commented on 17 January 2022

Great! I was going to get back to you.

Best regards,

Ariel

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.