July 26, 201213 yr $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.
July 28, 201213 yr 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.
July 28, 201213 yr Author You right Doughemi., Having the same doubt whether it will support for multi-user ! anyway thanks for the great support and valuable reply,
July 28, 201213 yr 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.
July 30, 201213 yr 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...
November 19, 201411 yr 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