3 Replies Latest reply on Jun 20, 2014 7:09 AM by azriley

    Translating Script - Equivalent of Set Field & Commit in PHP API?

    azriley

      Have a script that registers students. Can someone please tell me the equivalents of `Set Field` & `Commit Records/Requests`?

      Thank in advance

      Aaron

       

      Highlights of that script are provided below:


      # GET RELATED TABLE (FROM CONTACTS)
      Go to Related Record [From table:“Register_IndFilter_Contacts_ContID”;Using layout: “Contacts” (Contact) ]

      # UPDATE REGISTER (individual ID, contact ID)
      Set Field [Register::zk_IndividualID; Register_Individual_Filter::zk_IndividualID]
      Set Field [Register::zk_ContactID; Register_Individual_Filter::zk_ContactID]

      Commit Records/Requests

      # UPDATE REGISTER CONTACTS (last registration date)
      Set Field [Register_Contacts_ContID::zc_LastRegistrationDate_d; Get(CurrentDate)]

      Commit Records/Requests

      # UPDATE REGISTRATION ACTIVITY (registration date, status)
      Set Field [Register_Contacts_ContID::zc_LastRegistrationDate_d; Get(CurrentDate)]
      Set Field [Register_Contacts_ContID::Status; "Active"]

        • 1. Re: Translating Script - Equivalent of Set Field & Commit in PHP API?
          beverly

          What happens when you call the script via the API? I recommend getting the

          CWP-PHP guide and going through the tutorials to see how this works.

          • 2. Re: Translating Script - Equivalent of Set Field & Commit in PHP API?
            Mike_Mitchell

            Aaron -

             

            The PHP API operates a bit differently from the FileMaker interface. It's based on an object model, where you follow a series of basic steps. In the case of updating an existing record, the steps look like this:

             

            1) Create a database object (log into the database / create a connection).

            2) Fetch the record to be edited using (typically) the getRecordByID method, where you specify the layout and the record ID of the record to be fetched.

            3) Set the fields to the necessary values using one or more setField methods.

            4) Commit the record using the commit() method.

             

            So your code might look something like this:

             

                 $DB_NAME = {name of database file}

                 $DB_HOST = {DNS name or IP address of host}

                 $DB_USER = {user name / account name web page should use}

                 $DB_PASS = {password web page should use}

             

                 $DB = new FileMaker($DB_NAME, $DB_HOST, $DB_USER, $DB_PASS);

             

            (The above portion is usually kept in a separate include file for security and repeatability purposes.)

             

                 $contact = $DB->getRecordByID('layout',$recID);     // Insert appropriate values for layout name and record ID here

             

                 $today = getdate();

             

                 $contact->setField('Register_Contacts_ContID::zc_LastRegistrationDate_d',$today);

                 (etc.)

             

                 $result = $contact->commit();

             

            You'll need to perform some error trapping (in case the code can't find the appropriate record, for example), and this is just a skeleton, but it should be enough to give you an idea.

             

            Have you read up on any of the API resources? It's probably a good idea to go through the literature prior to setting up a site.

             

            http://www.filemaker.com/support/product/docs/12/fms/fms12_cwp_php_en.pdf

            http://www.formulationspro.com/pages/products/downloads/139.pdf

            https://jonathanstark.com/fm/filemaker-api-for-php-documentation.php (A little dated, but mostly still correct)

             

             

            Mike

            • 3. Re: Translating Script - Equivalent of Set Field & Commit in PHP API?
              azriley

              @Beverly - Unfortunately, since the script depends on variables set by the UI I wouldn't be able to call the script directly. That would be great though and I do see that in the documentation (executing scripts).

               

              @Mike - Exactly what I needed. I was confused by the related record vs regular record aspect, having been deep into other aspects of the API...that last link makes me wish I would have posted to this forum sooner. Should be page 1 of the API. Thanks!