Rename File/Image attachments
Asked by Matthew Fulton:

I have a form that requires the attachments submitted with the confiform be named with specific naming convention. There are two problems that I am having; first, how to access the attachment file name from the confiform macros; second how to change the names of multiple attachments.

My first thought was to use a IFTTT onCreated rule, but that there is only delete or copy attachment. I thought if I could copy the attachments to a page and use an onModified IFTTT rule I could change the name that way. Neither approach has proven to work beyond the copy of attachments to a new page.

Users can upload docs to the form and the form needs to transform the doc:

example.pdf to asAttachment.displayTitle=\[entry.my_Field\]_\[entry.my_Field1\]_\[entry.my_Field2\]\[entry.my_Field3\]\[entry.my_Field4\]_BU\[entry.asAttachment(0)index#\]_\[entry.my_Field5\]_\[entry._now.formatDate(yyyyMMdd)\]

WTC000000_3333_AD22221111_BU(1-#)_$250_20210407

The BU(#) just needs to be the index number for the attachment.

Is this operation even possible with the ConfiForm toolset?


Answers:
author: Alex Medved _ConfiForms_
body: You can use asAttachment function to establish a bridge to Attachment object that can be queried for any property it has, including the "displayTitle" - <https://wiki.vertuna.com/display/CONFIFORMS/Virtual+functions>

Renaming attachments is **not** currently supported by ConfiForms natively

The only option you have at the moment is to set up a web service request and use something like <https://docs.atlassian.com/ConfluenceServer/rest/7.11.2/#api/content/{id}/child/attachment-update>

Alex

comments: author: vidourem
body: Hello [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630)

I need to copy an attachment to a created page and rename the file name. No problem creating the page and attaching the file, however I can't use the API for security reasons. When I rename the file manually using the properties of the attachment it changes the "form page" field of the macros of the created page by doubling the name of the space. example: "space: space: page" the macros cannot work without manually modifying the "page of the form" field.


author: Alex Medved _ConfiForms_
body: Hi

Is this related to ConfiForms in any way? Could you be more specific?

Thanks

Alex


author: vidourem
body: Re [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630)

It is in connection with Confiforms. I use an ifttt macro to create a page with a tableview macro inside and then use another ifttt macro to copy an attachment to the created page. It works very well.

However when I rename the attachment with the Attachments Properties ability of Confluence it changes the link to the Confiforms form page of the tableview macro by doubling the name of the Confluence space.


author: Alex Medved _ConfiForms_
body: Could you help me to understand how to reproduce this?

Where does it "double" the space name? Any screenshot?


author: vidourem
body: It is the pageTitle attribute which is modified following the renaming of the file. No problem as long as you don't change the file name.

The attachment was copied after it was appended to a form with the ConfiForms Form Field Definition macro with the Field type = File / attachment attribute.

I will try to add the attachment to the form without using this macro, I have a feeling that might work. I will keep you informed.

![pageTitle-twice.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/151147i15E1107347716B00/image-size/large?v=v2&px=999 "pageTitle-twice.PNG")![macro-TableView.png](https://community.atlassian.com/t5/image/serverpage/image-id/151142i3C69F60CB1F38DDD/image-size/large?v=v2&px=999 "macro-TableView.png")


author: vidourem
body: I found a workaround, I added a text field named "pageForm" valued with the name of the page where the form is located. Then I use \[entry.pageForm\] in pageTitle of the TableView macro included in the body of the ifttt macro that creates the page. I don't know why but this way the problem goes away.


Tags: attachment

confiforms

confluence-server

ifttt

rename

server