Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Copying content from fields in the previous record

Featured Replies

Hi,

I'm trying to make a script that copies the content of about 30 consecutive fields from the previous record into the same field on the current record. My current solution is to, one by one,

go to previous record

copy field x

go to next record

paste field x

This makes for a long, tedious and inefficient script that takes a long time to execute. Is there a better way?

Thanks

Andrew

Create a global field called gPrimary. Create a relationship from gPrimary to the PrimaryKey of your table. We'll call this relationship "Primer". Go to the record with the relevant data and set gPrimary as the PrimaryKey. ie: SetField (gPrimary ; PrimaryKey). Now go to the record where you want the data and use the SetField script based upon this relationship. So, in full:

Go to Previous Record

SetField (gPrimary ; PrimaryKey)

Go to Next Record

SetField (MyField ; Primer::MyField)

SetField (MyField2 ; Primer::MyField2), etc, etc.

Peter

  • Author

Thanks, works like a charm!

Another question about this.

Before I export this database, I need to change all the field names. The way I can think of to do it is by exporting into a separate filemaker file with the correct field names and then exporting that file, but that seems kind of backwards. Is there a way to automate this process within the same file?

Thanks again!

Create a global field called gPrimary

This is not really 7.0 but more the way it was done in previous versions, when networking is most of the calculations NOW done on the server to prevent hogging network bandwidth, with one exception namely global fields. I'm not saying they should be avoided as in OOP but the new feature Get(ScriptParameters) are there to solve this particular issue.

--sd

Hi S

Nah, just use Auto Enter Calculation, Value from last visited record.

Value from last visited record means exactly that. So you better make sure you are IN the previous record (in a field) before you use that.

Picnichouse, what are you exporting to? Filemaker? Text? It must be text, or else you'd be done after changing the names in the other FileMaker file. XML export would allow you to create whatever field names you want. As a first line, right? What separators? Otherwise what do you mean by "field names" in a text file? XML/XSL would be little tedious, basically hand-building the first line as text; but it would work.

  • Author

Yes, I'm exporting to text (csv). I need the first record to hold the header names. Right now I'm doing it by exporting to another filemaker database with the correct field names and then exporting a text file from there. I'd like to be able to do it within the same file if possible.

Also, the fields need to export in a different order than order of creation.

Thanks for the help!

This is how you could do it with an XSL stylesheet file (which you could actually export from FileMaker). But you solution of using a separate FileMaker file is a good one also.

This example is more or less what you get with a "Merge" export out of FileMaker; comma-separated; field names in the first row, no quotes; data in other rows, with quotes.

But you can see I explicitly put the separators in each place. I also moved the order of the "field names" around a little. I did not move the order of the field data around. You don't really need to; because you can export in the order that you want directly from FileMaker. It's only the "fake" names that you need put the same as what you want to export.

ArbitraryFieldsCSV.zip

Fenton's solution is probably best for this situation, but for other uses I find it easiest to go to the previous record, set a global with its id, return to the original record, and set all the fields using Set Field [fieldX; rel::fieldX], where rel is a relationship from the global to the table's id.

Alternatively, you can set the global with the new record's id, go to the previous one and use Set Field [rel::fieldX; fieldX], then return to the new record.

Either method should take about the same amount of time.

  • 11 months later...

These are simple instructions and I believe I've followed them in spirit. For Peter1's instructions I have done the following:

create a global field called gPrimary

create a field called serNo and auto enter a serial number

create a field called filename which holds the text string of a filename

create a field called prevre which should receive the filename field of the previous record.

and created the following script

Go to Record/Request/Page

[ Previous ]

Set Field [ MyTable::gPrimary; MyTable::serNo ]

Go to Record/Request/Page

[ Next; Exit after last ]

Set Field [ MTable::prevrec; primer::filename ]

I apologize if this is so obvious, but I'm not seeing it.

Looking at the above, I'm not sure how the relationship between gPrimary and serNo comes into play, other than the last line of the script.

But I'm getting zero but I'm not seeing why it's not working, thanx, sam

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.