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.

Featured Replies


$rec =& $fm->newAddCommand('employee');

$rec->setField('name', 'Jack');

$result = $rec->execute();

With the above code i have successfully inserted the "Jack" record to the filemaker table.

Here i would like to get he last inserted record id..

Is any predefined function available for this to get "last record id".. if you know please help me to resolve this solution.

Many thanks in advance for your valuable reply.

Not that I know of. I had to create a work-around that looks like this:

$rec =& $fm->newAddCommand('employee');

$rec->setField('name', 'Jack');

$result = $rec->execute();



$findRec = $fm->newFindCommand('employee');

$findRec->addFindCriterion('name', 'Jack');

$result = $findRec->execute();

if( FileMaker::IsError($result)){

die('no records found<br>');

} else {

$recs = $result->getRecords();

$count = count($recs);

$lastID = $recs[$count-1]->getRecordID();

echo '<br>record id = ' .$lastID . '<br>';

}

Basically, this code creates the record, then searches for the data you entered into the record. Since this data may be the same as previously entered records, you have to go to the last record in the found set, and get the RecordID of that record.

Caution: I am not sure that this is totally multi-user safe.

  • Author

You right Doughemi.,

Having the same doubt whether it will support for multi-user !

anyway thanks for the great support and valuable reply,

The only multi-user issue I can imagine would be if someone else created a record with the same "name" field value at almost the exact same time - which probably isn't very likely in most use-case scenarios.

Using an exact field match search will reduce this from happening as often:


$findRec->addFindCriterion('name', '==Jack');

The only other method I can think of would be using a script to create the record. I'm not quite sure how you would get the result of the script, but I think that question has been asked (and answered?) on these forums.

Hmmm - I thought the return values from an insert was the record just created - that's certainly how FX.php handles it. So you can just get the actual -recid from the data returned back from the create...

  • 2 years later...
  • Newbies

Yes, the result is a normal FilemakerResult, so just use:

$rec =& $fm->newAddCommand('employee');
$rec->setField('name', 'Jack');
$result = $rec->execute();

$rec_id = $result->getLastRecord()->getRecordID();
$created_name = $result->getLastRecord()->getField('name',0); # or any other field, also autofill

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.