Bobby
Bobby

Reputation: 1595

For the FileMaker Script Step "Set Next Serial Value", how can I specify the table and field name dynamically?

I'm writing a script that's intended to work for multiple layouts and table occurrences. For each, it will determine the primary key and then find the maximum value in any record for that primary key field. That's all working well. Now, I've computed my intended next serial value and would like to assign this to a field whose name I have saved in a variable. I am unable to specify the target field by using a variable. I only see an option for selecting the table and field from a list of existing fields.

My questions:

I've tried:

As you might notice, I'm relatively new here, so I would also appreciate any tips about how I can improve the formatting or content of this question.

Set Next Serial Value

Upvotes: 0

Views: 1125

Answers (1)

Chuck
Chuck

Reputation: 4892

Before we had Set Next Serial Value, we used Replace Field Contents to get the same effect, but it's more complicated, although it will allow you to do it dynamically. The basic idea is that you'll need to be on the record that has the maximum serial number, isolate that record, make sure you're on a layout with the serial number field, go to that field, and use Replace Field Contents to set the field to itself while also updating the next serial value. The script would look something like this:

Go to Layout [ // layout that has the target field ]
Enter Find Mode
Set Field By Name [ $_target_field ; $_max_serial ]
Perform Find
Loop
    Go to Next Field
    Exit Loop If [ Get(ActiveFieldTableName) & "::" & Get(ActiveFieldName) = $_target_field ]
End Loop
Replace Field Contents [ No Dialog ; Replace with serial numbers: Custom values ; Initial Value: $_max_serial ; Increment by: 1 ; Update serial number in Entry Options ]

No, I haven't tested this out on a sample file, but it's the basic technique we used before FileMaker, Inc. gave us Set Next Serial Value.

Upvotes: 1

Related Questions