Linking to an attachment in text/xml transformation

Guy Allen asked on April 12, 2017 20:43

I need to create a hyperlink in a text/xml transformation to an attachment in a field. Having no luck.

Correct Answer

Rui Wang answered on April 12, 2017 22:16

<a href={% GetFileUrlByGUID(FieldName, "", "") %}">XXXXX</a>

0 votesVote for this answer Unmark Correct answer

Recent Answers


Rui Wang answered on April 12, 2017 21:51

Is this field a "file" type and you use "direct upload" form control when defined in page type?

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 21:56

Document Attachments type and Document Attachments control. Should I change them?

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 12, 2017 22:00

You can use this macro method {% GetFileUrlByGUID(FieldName, "FileName") %}

I know that works with File type and Direct upload, not sure about Attachment, you can try it first.

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 22:14

I don't want to list a filename though since I'll be using this across several files, just the fieldname and pull back the url of its attachment if possible.

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 22:28

Thanks, but it still only shows the current page url I'm on when I try it. Most things I've tried do the same.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 12, 2017 22:32

I just tested, the Attachment didn't work. So change your data type to File and use Direct Upload form control. The above HTML with macro would get you something like this

http://localhost/getattachment/524d45da-2f8c-4adb-b699-56af180f095f/

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 22:41

Yes, this works perfectly now except I have to list the filename...that's still a problem. Anyway around that?

{% GetFileUrlByGUID(FieldName, "FileName") %}

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 12, 2017 22:43

You don't need to enter the file name

{% GetFileUrlByGUID(FieldName, "", "") %}

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 23:07

You sir, are a genius! Now I have one thing left to figure out. I need to create a field for a user to supply a link if he has no file to upload. Once I create the new field, I need to figure out how to make the code know that if there is no file attachment, then use the link supplied in the new field I'm creating...if that's understandable.

Users are basically going to either download an attachment or link to something else when they come to the site and click.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 12, 2017 23:12

It would be easier to check if the manual Link field (e.g. LinkURL as the field name) is empty or not.

So something like

{% if (LinkURL == "") %}
<a href={% GetFileUrlByGUID(FieldName, "", "") %}">XXXXX</a>
{% } else { %}
<a href={% LinkField %}">XXXXX</a>
{% } %}
0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 12, 2017 23:19

I see what you mean. That would be a better way. I'll try it out in a bit. Thanks Rui!

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 14, 2017 15:05

Not quite working yet.

0 votesVote for this answer Mark as a Correct answer

Guy Allen answered on April 14, 2017 20:08

Got it working....thanks again, Rui!

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 14, 2017 21:16

Cool, please mark the right answer is you can :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.