Script not updating filename field when adding container file

In a container field, I have an on-modify script step to set a "file name" field in the same portal row with the filename from the file added to the container using getcontainerattribute(<container_field>; "filename").

What happens is when I drag a file to the container once, the file name field does not update. However, if I drag the file to the container field again, THEN the filename field (usually, but not always) updates.

Here's the entire on-modify script for the portal container-row field:

Set Field [ Attachments::File Name ; GetContainerAttribute ( Attachments::attachment ; "filename" ) ]
Commit Records/Requests [ With dialog: Off ]

I thought initially this problem had something to do with FileMaker adding a new portal row and the reference to the current portal row being not correct. However, the same issue happens if I try to add a file to a container field with other portal rows beneath it.

Suggestions?

Thanks in advance.

Thanks,

Not sure but could it be you have to commit the record after adding the file to the container. Than you can extract the name And set the field and recommit.

Just a guess. Not in front of fm right now.

Else I would experiment with the getfieldname function instead of just entering the fieldname.

The commit idea is a good one and I had tried that. The best approach I found was to use a auto-enter function that apparently fires before something else gets in the way and keeps getcontainerattribute (or GetAsText() from working.

Thanks for your reply.

I think you are bumping into a situation that is discussed in notes for OnObjectModify.

The value of the script parameter that OnObjectModify passes to your script is determined before this script trigger is activated. If you set OnObjectModify to activate on a field object, your script is run after the field is modified. Therefore, if your script needs the value before the field was modified, use the script parameter to pass the field's unmodified value into the script. However, if your script needs the modified value, include a step in the script that gets the field's current (modified) value.

Read the note carefully. If you pass the field value to the script via the script parameter you are going to pass the unmodified value. If you get the field value via a script step within the script you will get the modified value.

3 Likes

Did the note make a suggestion how to get around that? LOL

Looks like the auto-enter function is the way to go.

Thanks @Malcolm.

Completely agree. Auto-enter is the way to go.

2 Likes