Guru Salem Posted July 26, 2012 Posted July 26, 2012 $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.
doughemi Posted July 28, 2012 Posted July 28, 2012 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.
Guru Salem Posted July 28, 2012 Author Posted July 28, 2012 You right Doughemi., Having the same doubt whether it will support for multi-user ! anyway thanks for the great support and valuable reply,
dansmith65 Posted July 28, 2012 Posted July 28, 2012 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.
webko Posted July 30, 2012 Posted July 30, 2012 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...
Newbies mmeier Posted November 19, 2014 Newbies Posted November 19, 2014 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
Recommended Posts
This topic is 3924 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 accountSign in
Already have an account? Sign in here.
Sign In Now