Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Find filename of an image
Tagged: image filename
- This topic has 6 replies, 3 voices, and was last updated 2 years, 3 months ago by Brendan.
-
AuthorPosts
-
January 12, 2022 at 6:40 AM #46279
Daphne TregearParticipantI would like to create a field which consists of the filename of the image included in a record. Is there a simple way of doing this?
For example, if my Image field is held in a file called Images/IMG_0122.HEIC for that particular record, I would like the field to contain IMG_0122.HEIC.
The icing on the cherry would be that for a few records there is more than one image contained in the Image field and I would like all of the filenames listed. If this is too complex I can live without.
This requirement is for a report I am sending in PDF format so that the recipient could, if they wished, turn to the Images folder (which I am also including) and look at the image(s).
I would be grateful for any help.
January 12, 2022 at 10:18 AM #46281
Daniel LeuParticipantI assume that all your PDFs are either
file attachments
orphotos
. This field script extracts the filenames and returns them as a comma separated list.You would need to adjust the
photo_id
field according to your form. Just get the id of thefile attachment
orphoto attachment
field.function Get_Filenames() { const photo_id = 'fld-xxx'; let filenames = [] let photos = record.getFieldValue(photo_id) console.log("Found photos:" + JSON.stringify(photos)); for (photo of photos){ filenames.push(photo.filename); } return filenames.join(', ') } Get_Filenames();
- This reply was modified 2 years, 3 months ago by Daniel Leu.
- This reply was modified 2 years, 3 months ago by Daniel Leu.
January 12, 2022 at 12:03 PM #46285
Daphne TregearParticipantThanks for your reply. I am unable to get it to work and I may not have described my problem well enough. Please bear with me.
I am creating my PDF by using the Print menu to save a PDF of a selection of database fields to a file on my system. This file, plus a copy of the images directory my database references, will be written to a flash disc and sent by post to someone. The person can then peruse the PDF and refer to the images if they wish. There may not be an image associated with every record, so the script must be able to cope with that.
Where a record does have one or more associated images my field called “Image” shows the image(s). I wish to set up a new field in each record (let’s call it “Image name”) which shows the filename of the image(s) (just the filename not the complete path). I can then include “Image name” on my printout so the recipient knows which filename to look at.
Does that make it clearer?
January 12, 2022 at 5:31 PM #46287
BrendanKeymasterHi Daphne,
The Field Script that Daniel wrote for you does exactly what you describe.
Did you adjust the
photo_id
value in the script to match up with the ID of the Photo field in your own form?When you said it didn’t work for you, what exactly happened? Were there any error messages in the console log?
Thanks,
Brendan
January 12, 2022 at 6:12 PM #46288
Daniel LeuParticipantJust set the field ‘Image name’ as a script and copy my code in there and adjust the
photo_id
according to your form.January 13, 2022 at 2:43 AM #46289
Daphne TregearParticipantBingo! All it took was a decent night’s sleep before I noticed that the id was staring me in the face on the Fields panel and that I could just cut and paste it into the script.
It barfed on TIF files for some reason but I can convert these.
Thank you for your patience and assistance.
January 13, 2022 at 2:45 AM #46290
BrendanKeymasterExcellent! I’m glad that’s working now.
-
AuthorPosts
You must be logged in to reply to this topic.