Pranav Krishna
Giga Explorer

Hi everyone I am @Pranav Krishna Teja Devireddy.I am writing this article to help you copy attachments from SERVICENOW to JIRA using flow designer. It works for other tables also. After reading many articles I haven't found articles that helped me in avoiding the duplicate attachments, So In this article We will cover everything..... Happy Learning.

 

Step - 1) Since I am trying to integrate SAFe story record and JIRA Story I went with JIRA spoke. So, first go to servicenow store and request JIRA SPOKE installation to your instance.

Step -2) Now after setting up your creation flows we now come to copying the attachments but when we use a copy attachments action from JIRA spoke it asks for Issue ID and and attachment as in below Picture now to tackle that we can use "LOOK UP RECORDS" Action.find_real_file.png

Step - 3) Now create a "LOOK UP RECORDS" action and fill out details like Table name,conditions and order by for reference see below pic,

                              Action - LOOK UP RECORDS

                              Table - SYS_ATTACHMENT

                             Conditions - Table SYS ID is "Your record SYS_ID

                             Order By - Created - Z to A or A to Zfind_real_file.png

Step - 4) Now we may have more than 1 attachment present so we use an "IF logic" see below pic for reference and we put condition as count greater than or is 1(to put this condition use data pill picker select the previous action and you will be able to see an integer object "count" see the below pic for reference )find_real_file.png

Step -5) Now we got our condition in place but we need these attachments to be looped so that we can copy them so for that we use an flow logic called "FOR EACH ITEM IN" and just like before we use data pill picker to select our attachment(see below pic for reference)find_real_file.png

Step -6) Now In Final step we use copy attachment and use data pill picker to fill out necessary details(see first pic for reference) and for attachment field part we navigate through data pill picker and select "FOR EACH ITEM IN" action(see below pic for reference) and for Issue id it is different for everyone(for us it was correlation ID).find_real_file.png

Step -7) Now we are able to copy our attachments to jira but if the flow is being triggered continously or if used for update the record would be duplicated so for that we first have to add a custom choice field in sys_attachment table and give it 2 choices 1.YES

             2.NO and now after doing this go to the flow we have configured and change the "LOOK UP RECORDS" Actions condition(see below pic for reference) to "and"   "yours custom choice field name"  is "NONE"find_real_file.png

Step -8) No for the final step we go and add an "Update Record" action under copy attachment and fill out necessary details like record,table,field

Record - Use data pill picker and again select "FOR EACH" > Attachment record(JUST LIKE STEP 6)

Table - Automatically Populated(IF NOT SELECT SYS_ATTACHMENT)

Field - Select  "yours custom choice field name"  and set field value to be YES(see below pic for reference)find_real_file.png

 

AND BOOM WE CAN COPY ATTACHMENTS TO JIRA AND ALSO AVOID DUPLICATES.

MARK HELPFUL IF YOU HAVE LEARNED SOMETHING NEW

Thanks,

Regards @Pranav Krishna Teja Devireddy 

Comments
sd2097
Tera Guru

Hi Pranav,

 

Thanks for the detailed documentation. We had a similar scenario and your documentation really helped.

 

Thanks,

Sudhangshu

SwarnadeepNandy
Mega Sage

I think, if you trigger the flow on sys_attachment table with suitable set of conditions, then you won't need Foreach loop.

I am looking for Deletion of attachment, can you please let me know, how that can be achieved.

 

Kind Regards,

Swarnadeep Nandy

sd2097
Tera Guru

Hi @SwarnadeepNandy ,

 

For deletion of attachments using JIRA Spoke, we were able to achieve that by triggering the out of the box 'Delete attachment' action in JIRA spoke using a business rule. We can do that. We just need to copy the code snippet from the action.

Now the catch is, the Delete attachment action takes the attachment ID as it's input. So, to get that, we had to get the attachment IDs from JIRA using the 'Look up latest attachment' action in JIRA spoke. We copied that action and customized the code to get the attachment IDs which we could use in the 'Delete attachment' action.

 

Hope this helps!

 

Regards,

Sudhangshu

adrian08
Tera Contributor

Anyone encountered permission issues here? 

 

I got an error something like: 

Error:  Either provided SysID of attachment record is incorrect or unknown error occurred.

 

Digging further, i got this:

IPaaSActionProbe | Error encountered fetching Attachment : Attachment does not exist or user does not have read permission on attachment with sysid <id removed>.

Josh Pirozzi
Kilo Sage

Hi @adrian08,

 

We're receiving the same error. Were you able to find a solution for it?

 

Thanks,

Josh Pirozzi

adrian08
Tera Contributor

@Josh Pirozzi  you have to ceate a Cross-Scrope Privilege (sys_scope_privilege) so JIRA can read the sys_attachment table

 

adrian08_0-1717767686136.png

 

DanielG
Tera Contributor

@adrian08 I had the same error "Error encountered fetching Attachment : Attachment does not exist or user does not have read permission on attachment with sysid" and I created the Cross-Scope Privilege.

 

However, I'm still getting the same error.

 

Here is a screenshot of my Cross_scope Privilege:

Screenshot 2024-09-26 at 4.30.56 PM.png

 

Was there anything else you might have done to fix your issue?

DanielG
Tera Contributor

FYI for others experiencing this.

I found a fix for my issue. It had to do with our mid server service account needing read access to sys_attachment table.

Version history
Last update:
‎04-27-2022 10:20 PM
Updated by: