Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

  • Newbies
Posted

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?

  • 1 month later...
  • Newbies
Posted

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.

Posted

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
Posted

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.

  • 1 month later...

This topic is 6109 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.