Newbies cdaveb Posted December 13, 2007 Newbies Posted December 13, 2007 I've just started working on converting some scripts from FX.php to Filemaker PHP API. I'm working on one that does an insert into the Filemaker DB, and there's an autogenerated order # that gets created when a record is inserted. I can't seem to figure out how to get that order # short of doing a second query to find the record I just inserted. In FX.php I was able to just inspect the result of the query for the data, and I found an example for FM API which said you could do that, but I've tried checking the result and all it seems to contain is 1. Is there any way to do this short of a second query?
Newbies Edmond Cho Posted January 22, 2008 Newbies Posted January 22, 2008 Hi, I just needed to do this for a user registration script. When I did a getRecords call on the result, I was able to use the getField method to get an id. $records = $result->getRecords(); $user = $records[0]; $user_id = $user->getField('user id'); I hope that helps.
Genx Posted January 22, 2008 Posted January 22, 2008 Just to clarify, the $result variable Edmond is listing is from the result of the entry command: $result = $add_cmd->execute(); You might also try $record = $result->getFirstRecord() rather than $records = $result->getRecords(); $record = $records[0];
Newbies cdaveb Posted January 23, 2008 Author Newbies Posted January 23, 2008 Thank you for your help guys! I had actually been trying to use getRecords but it never worked for me, but Genx's reply actually helped me figure out the problem. In the PDF file that comes with Filemaker 9 describing the Filemaker PHP API, there are actually two separate methods described for adding a record. I'd forgotten this was the case, when I first wrote my script I just copied out one method and since it inserted a record just fine I'd forgotten there were two. It turns out that if you use the createRecord and commit method to create your record, all you get as a result is a boolean value. This is the method I was using. The newAddCommand and execute method however returns an object that can be inspected for the data. I have no idea why the two different methods exist and why the documentation doesn't explain the difference between the two but now I understand why I couldn't get the data out and how to get it. As an interesting sidenote, it turns out that if you do use createRecord, once you do the commit, you can inspect the object you used for the createRecord to find the data from the insert as well, which certainly was behavior I wasn't expecting but the data is in there. So it is possible to get it via that method if you know where to look. Thanks again for the assistance, this was the major stumbling block I was having on my script conversions so now I can move forward.
Peter Bowen Posted February 23, 2008 Posted February 23, 2008 I love you guys! I've spent half the day trying to figure this out and then I discovered this thread - thanks Cheers Pete
Recommended Posts
This topic is 6378 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