Help

Re: Upload files in correct sequence to attachment

Solved
Jump to Solution
2497 4
cancel
Showing results for 
Search instead for 
Did you mean: 
John-Paul_Kerno
7 - App Architect
7 - App Architect

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!

40 Replies 40

Indeed, you would think that would solve it. I did this by changing the field in the table to “attachment” but no such luck.

Screen Shot 2020-06-17 at 13.53.12

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.

Hi,

Here is the original output from your first script (pre amended)
Screen Shot 2020-06-17 at 15.37.16

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?

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).

image

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?

John-Paul_Kerno
7 - App Architect
7 - App Architect

Unfortunately same output. Refreshed screen still shows images in original bulk add non sequential order. Maybe I am not using correct script?Screen Shot 2020-06-17 at 16.25.55

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?

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.

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.

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

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);