Acces {{issue...}} smart value inside a list
Asked by Cow Hills:

Hi All,

I recently created a JIRA automation rule that send a email when een registration of software is done successful for a customer.  
This is working fine for 99% the only problem is with the link to attachments.

i use the following way to add a list of attachments  
{{#issue.attachment}}  
\<a href="{{content}}"\>Attachment: {{filename}}\</a\>  
{{/issue.attachment}}

This is working fine for our employees that have a JIRA license. but the link generated from {{content}} is not accessible for our customer that have only a JIRA Customer account.

the link that is generated is

[https://\*JIRA URL\*/secure/attachment/\*AttachmentId\*/\*AttachmentFilename\*](https://portal.cowhills.nl/secure/attachment/41656/FileSignatureReport_1.145.100.35.html)

When i login the to the customer portal the url that the customer see from there is as followed  

[https://\*JIRA URL\*/servicedesk/customershim/secure/attachment/](https://portal.cowhills.nl/servicedesk/customershim/secure/attachment/41656/41656_FileSignatureReport_1.145.100.35.html?fromIssue=30802)[\*AttachmentId\*](https://portal.cowhills.nl/secure/attachment/41656/FileSignatureReport_1.145.100.35.html)[/](https://portal.cowhills.nl/servicedesk/customershim/secure/attachment/41656/41656_FileSignatureReport_1.145.100.35.html?fromIssue=30802)[\*AttachmentId\*](https://portal.cowhills.nl/secure/attachment/41656/FileSignatureReport_1.145.100.35.html)[_](https://portal.cowhills.nl/servicedesk/customershim/secure/attachment/41656/41656_FileSignatureReport_1.145.100.35.html?fromIssue=30802)[\*AttachmentFilename\*](https://portal.cowhills.nl/secure/attachment/41656/FileSignatureReport_1.145.100.35.html)[?fromIssue=\*issueid\*}}](https://portal.cowhills.nl/servicedesk/customershim/secure/attachment/41656/41656_FileSignatureReport_1.145.100.35.html?fromIssue=30802)

So i thought i wood created the URL for the email my self.

{{#issue.attachment}}  
\<a href= "\*JIRA ULR\*/servicedesk/customershim/secure/attachment/{{id}}/{{id}}_{{filename}}?fromIssue={{issue.id}}"\>Attachment: {{filename}}\</a\>  
{{/issue.attachment}}

But the problem is that the smart value ((isue.id}} is not giving the value back i think it is because it is inside the smart value list. when i use the {{issue.id}} outside the list it is working.

How do i use the {{issue.id}} in the smart value list  


Answers:
author: Cow Hills
body: Oke i fixed it by making a Scriptrunner field for it.  

```
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def baseurl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")

def issues = [issue] as List<Issue>
issues.addAll(issueLinkManager.getOutwardLinks(issue.id).collect {it.destinationObject})
issues.addAll(issueLinkManager.getInwardLinks(issue.id).collect {it.sourceObject})

issues.collect { issue ->
issue.getAttachments().collect { att ->
"<a href=\""+ baseurl+ "/servicedesk/customershim/secure/attachment/" + att.id + "/" + att.id + "_" + att.filename + "?fromIssue=" + issue.id + "\">" + att.filename + "</a>" + "<br/>"
}
}.flatten().join("")

```

That field i used to show me the links in the send email.  
the only down side is that i show all attachments from the issue even when te customer does not have the proper rights for it.


author: Bill Sheboy
body: Hi [@Cow Hills](/t5/user/viewprofilepage/user-id/1332029)

This is inside of the iterator processing for {{#issue.attachment}} so have you tried just {{id}} by itself?

Best regards,

Bill

comments: author: Darryl Lee
body: My read on this was that {{id}} is returning the id of the Attachment, and they're hoping to refer back to the Issue id.

Would a (gulp) variable work?

{{origid}} = {{issue.id}}

And then try using {{origid}} in the list iteration?


author: Cow Hills
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,   

thanks for you answer {{id}} wil give back the attachment id but i need the id for the issue it self.


author: Cow Hills
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) ,  

Thank you for the suggestion.  
I have tried the following

{{origid}} = {{issue.id}}

{{#issue.attachment}}  
\<a href= "https://\*JIRAURL\*/servicedesk/customershim/secure/attachment/{{id}}/{{id}}_{{filename}}?fromIssue={{origid}}"\>Attachment: {{filename}}\</a\>  
{{/issue.attachment}}

but still nothing.  
i not even sure that the {{origid}} variable is working i am also unable to find anything about it in the documentation for JIRA Automation Server.


author: Darryl Lee
body: [@Cow Hills](/t5/user/viewprofilepage/user-id/1332029) does the link work without **?fromIssue=\*issueid\***?

Like in an incognito session, does this work:

https://\*JIRA URL\*/servicedesk/customershim/secure/attachment/\*AttachmentId\*/\*AttachmentId\*_\*AttachmentFilename\*

Because I wonder if the fromIssue part might be optional.


author: Darryl Lee
body: Sorry, when I wrote {{orgid}} = {{issue.id}} I was suggesting that you use the **Create variable** action to set the value. Example:

![var2.png](https://community.atlassian.com/t5/image/serverpage/image-id/133923i4D73F7C4F7882207/image-size/large?v=v2&px=999 "var2.png")

<https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Create-variable-New-component/ba-p/1448118>


author: Cow Hills
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322)   

No without the ?fromissue=\*issueid\* it is not working it will get a HTTP Status 400 -- Bad Request

For the Create Variable function there is not support for the Server version and that is the one we use not the cloud version of JIRA.


author: Darryl Lee
body: Ahh, thanks for clarifying. I was just looking at my Cloud instance and did not see that attachment format at all. (You tagged this question as **cloud**, so that's why I was working from that assumption.)

I've unfortunately not had the opportunity to work with Automation on Server.

Reading [this bug](https://jira.atlassian.com/browse/JSDSERVER-1361), I wonder if a possible workaround might be to add a comment with the attachment referenced thusly:

\[\^attachmentname.pdf\]


author: Bill Sheboy
body: Hi [@Cow Hills](/t5/user/viewprofilepage/user-id/1332029)

Now that we know you are using Jira Server, I would like to suggest a pause and ask you to post an image of your entire automation rule. That may provide more context for the community to offer ideas.

Thanks!


author: Cow Hills
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)   

please see the following printscreen of the send email part of the automation rule.  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/134458i9B6805F4579FA4D7/image-size/large?v=v2&px=999 "image.png")


Tags: cloud