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.

create record ; how do I get the primary key of that record

Featured Replies

LS,

 

This must be so simple, but don't get php and how it works not very well with php ( using newAddRecord and execute ).

 

I have created a new record and set data in that record.

 

The questions I have are :

1. how do I set more data in the same record ?

2. when I create the record can I get the contents of an auto-enter create primary-key field back as a result ?

 

Hope this makes sense !

 

TIA

 

Joost

Before you can do #1, you have to do #2

//the part you have now
//
$newRecord = $fm->newAddCommand('YourLayout');
$newRecord->setField('theField', 'theData');
$result= $newRecord->execute();
//
// The part you need to add
//
$getAllRecords = $fm->newFindAllCommand('YourLayout');
$gotAll = $getAllRecords->execute();
$records = $gotAll->getRecords();
$count = count($records);
$lastID = $records[$count - 1]->getField('PK');// your auto entered  primary key field
$recID = $records[$count - 1]->getRecordId();

Now you can edit that record:

$addData = $fm->getRecordById('YourLayout'; $recID);
$addData->setField('theOtherField', 'theOtherData');
// etc for other fields
$done = $addData->commit();

Note that $recID is not your auto entered ID field; it is FileMaker's internal record ID.

 

Of course, if you are populating the other fields at the same time you create the record, you just keep adding setField commands after the newAddCommand step.

I moving towards not using any PHP API commands except Perform Script.

 

I'm inclined to just let it all run as FileMaker scripts and only use GetField to pull messages from a one field table.

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.