Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7013 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi Gang,

I am attempting to import a folder of images to one of my tables. I go through the "Import Records" step, and select "Folder" and images. I am only storing a reference to the image. What I also need to do as I import the images into the table, is to automatically assign an ID field to each new image/record, that comes from another field in another table. In the one import process, all the images will be assigned this same value. But on another import, the ID may change. How can I achieve this with Scriptmaker. I am new to the FM world so I apologize if this is too basic a question.

Many thanks,

Nando

Posted

I dont think you can read in and import a folder of files even in FM8 without the Troi File Plug-in.

I used the plug-in to have the user select a directory and then read in all the files in that directory and then import them into a table in FM7.

Posted

What I also need to do as I import the images into the table, is to automatically assign an ID field to each new image/record, that comes from another field in another table. In the one import process, all the images will be assigned this same value. But on another import, the ID may change. How can I achieve this with Scriptmaker.

First, John, you can import a folder of images, which is what Nando is doing without a problem. What he/she wants to do is to assign all the records imported an ID from another table.

What you need to do is to run a scripted operation just after the Import Folder, while the records are still the found set. It could be a Loop, with Set Field [] or a Replace Field Contents [], to put the ID into its field in all the records. You are going to have to put the ID into a global field first (or into a Script Parameter {from a button}, or into a Script Variable {8 only}). Since we don't know exactly how you're going to pick this ID from the other table, we can't really say which of these is best. But it needs to be in something that is accessible from all records in the images table.

If, for example, you are running the script from the table with the ID (which makes the most sense, since you have to choose the ID otherwise), then you know what ID you're on. I'm going to set it into a global in the script below.

Freeze Window

Commit Records [no dialog]

Set Field [ global ID, ID ]

Go to Layout [ Images (Images table) ]

Import Folder [ the images folder ]

Go to Record [ First ]

View As Form (if it is a list view)

Loop

   Set Field [ Images::ID, Other table::global ID ]

   Go to Record [ Next, exit after last ]

End Loop

Go to Record [ First ]

View As List (if it was a list view to start with)

Commit Records [no dialog]

(P.S.

1. You can set or get a global from any other table occurrence. Doesn't even require a relationship.

2. View as Form will make a Loop go many times faster on a List view layout. But you want to switch back when you're done. If it's a Form view to start with you don't need those steps.

)

Posted

I believe you can save yourself the entire post-import operation, by defining the ID field to auto-enter the globalID. Then it's simply:

1. Set globalID to desired value;

2. Import (with "Perform auto enter.." selected).

Posted

Thank you Fenton. A quick question before I try this. How can I loop through the records and assign it the global value, if I have other photos on the table with a different ID (that is not meant to change)?

Thank you very much!!

Nando

Posted

You don't have to worry about other records. Because after an Import of new records you always have only the records that were imported as the found set. Loops only work within the found set.

But use comment's advice. It is a much better way to get the ID automatically, at the same time as the Import; no script needed afterwards. Leave the [x] Allow auto enter calculations checkbox checked (the 2nd dialog of the import).

This topic is 7013 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.