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

How do I set an id field based on result of other field matching

Featured Replies

  • Newbies

I'm new to FM so correct me if I am wrong with any statements or assumptions:

I have 2 tables.

product

id

cat_id

tmpCat

Categories

id

Category

Categories has unqiue values in 'Category' cloumn.

Products has multiple rows with the same value for 'tmpCat'.

I am trying to set for each row:

'Products::cat_id' = 'Categories::id' where Products::tmpCat = Categories::Category

I want to do this for all rows in Products.

The reason:

yes Products is not normalised as 'tmpCat' should not exist but this is due to an import from a non normalised table that combined both Products and Categories (and others tables not mentioned) together.

I could only import to one table at a time so I imported from the existing table twice ( once for Products and again for Categories ).

I then removed all duplicates from Categories.

I have created a realtionship between Products::cat_id and Categories::id.

In SQL it would be simply a matter of :

UPDATE Products p SET p.cat_id = (SELECT c.id FROM categories c WHERE c.category = p.tmpCat )

thank you in advance for your help.

Edited by Guest

You just need to do a "switcheroo." This is pretty common when you are building from flat-file data. Just as you have a tmpCat field, with the full Category name, you need a temporary relationship, from tmpCat to the Category name in Categories. Assuming that spelling is consistent you should be able to do a Replace (on all Product records), with Calculation, using that temporary relationship, putting the id field from Categories into the Products cat_id field. Then you can delete the temporary field and relationship.

(P.S. In case you don't know, to do a Replace put your cursor in the cat_id field in Products. Be sure to backup first, as Replace cannot be "undone," and it's possible to mess up the field in the entire table.)

  • Author
  • Newbies

THANKS!!

got the same answer from Nelluk ( #filemaker irc on efnet ).

Funny thing he tried to explain this yesterday to me but didn't use the important term 'switcheroo' which explains the action quite well (seriously).

I kept forming a duel relationship (id + category) which obviously failed.

Create an account or sign in to comment

Important Information

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

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.