Jun 16, 2020 05:39 AM
I am trying to upload several jpgs to one record. I use ‘Gallery’ and drop files in bulk to the plus sign bottom right. They are pages from a book and therefore in a sequence. The files are numbered as jpgs in a numerical sequence.
Why can I not have the viewed output remain in the correct sequence?
Why is the output always reversed with the last item first?
How can I fix this?
Many thanks if anybody can help!
Solved! Go to Solution.
Jun 17, 2020 05:54 AM
Indeed, you would think that would solve it. I did this by changing the field in the table to “attachment” but no such luck.
Jun 17, 2020 06:58 AM
Sorry, I originally hardcoded the field name but didn’t make all the necessary adjustments after adding the field picker. I edited the script in my original post so it should work now.
It looks like the script ran in your second screen shot. Can you expand the little triangles next to the “object” lines until we can see the file names of the attachments?
Note that these are just quick little utility scripts and do not have much in the way of output.
Jun 17, 2020 07:49 AM
Hi,
Here is the original output from your first script (pre amended)
I ran your amended script - the first one in the thread above 'sort attachments for a single record in alphabetical order by filename"
The output error is exactly the same. But that’s because the script is the same as far as I can see?
Jun 17, 2020 08:14 AM
Thanks for the screen shot. Do you see that each of the 51 objects also has a little triangle next to it? If you keep expanding the triangles until all the nested triangles are expanded, you should see filenames. Here is what the expanded triangles look like on my computer. I’ve put red ovals around the filenames in the original order (not alphabetical), and green ovals around the filenames in the new order.(alphabetical).
This is the expected output of the script, as it was just a quick utility to demonstrate re-arranging attachments. (When people hire me to write a script, I make the output a bit prettier.)
The correction I made to the first script was just in one line. I changed "attachment"
to [field.name]
. Originally I harded-coded the attachment name, and now it is in a variable.
Note that the second script has no output at all. It just updates the records. So you have to look at the actual attachments in the records to see that they have changed. When you look at the records, has the attachment order changed?
Jun 17, 2020 08:30 AM
Unfortunately same output. Refreshed screen still shows images in original bulk add non sequential order. Maybe I am not using correct script?
Jun 17, 2020 11:47 AM
Notice that before you expand the triangles, there are two triangles. The first one is the attachments for the record before the update. The second triangle is the the attachments after the update, so that you can see that they are different.
What do you see when you expand the second triangle?
What do you see when you look at the attachments in the actual field?
Jun 17, 2020 01:53 PM
I have expanded the results of both sets and they are exactly the same. Same non sequential order. The order does not change in the field.
Jun 17, 2020 02:54 PM
I’m sorry the script does not work for you. As the script works on my setup (as you can see in my screen capture), there isn’t much more I can do.
I hope you find a solution to your problem.
Jun 17, 2020 04:06 PM
Hi, I figured out that the script will only run on limited number sequences such as
1.jpg
2.jpg
3.jpg
It will not run on leading zeroes
001.jpg
002.jpg
or when the filename has any characters, even if characters preceded by any sequence.
But, it will run when sequence numbers are after any characters (NAME-1.jpg, NAME-2.jpg, but not if the sequence has preceding zeroes, ie NAME-001.jpg, NAME-002.jpg
Jun 17, 2020 04:55 PM
Thank you for this additional information. This might have to do with the way JavaScript compares strings.
Try replacing this line …
return a.filename > b.filename
with this line …
return a.filename.localeCompare(b.filename);