Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 3725 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted


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

Posted

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.

Posted

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.

Posted

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
Posted

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

This topic is 3725 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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