Forum Discussion

Re: When using the Quickbase JSON API is there a way to add a new created relationship field to the form similar to when creating a normal field?

Yeah that's fine, anything that works I will take a look.



------------------------------
Chris Baker
------------------------------

4 Replies

  • Gary1's avatar
    Gary1
    Qrew Assistant Captain

    It's a two-step process per field.

    First, use this endpoint to add the new field:

    https://helpv2.quickbase.com/hc/en-us/articles/4418302265236-API-AddField

    At minimum, you'll want to pass mode, type, and add_to_forms. Type must match the field type of the intended lookup field in the parent table.

    Also, make sure your legacy form is set to "Auto-add new fields". (I have no idea what will happen with the new form styles.)

    <mode>lookup</mode>
    <type>text</mode> // must match intended lookup field!
    <add_to_forms>1</add_to_forms>

    Second, use this endpoint to update the the lutfid and lusfid attributes of the newly created field:

    https://helpv2.quickbase.com/hc/en-us/articles/4418310972052-API-SetFieldProperties

    <lutfid>8</lutfid> // the field ID of the reference field in the same table
    <lusfid>6</lusfid> // the field ID of the source field in the lookup table

    lutfid and lusfid are not in the XML API documentation, but they are visible when you call API_GetFieldProperties on a lookup field. For some reason, they are ignored when passed to API_AddField, but they are accepted when passed to API_SetFieldProperties.

    I tested this out and it all works: the field is created, it's a lookup, and it appears by default on the legacy form. 

    IMO, this method is going to require a lot of overhead to script/automate. If I were in your shoes and this was a one-time operation, I would consider using the JSON API to create the fields (very easy) and manually add them to the form (painfully monotonous). 

    Good luck!



    ------------------------------
    gary
    ------------------------------
    • ChrisBaker2's avatar
      ChrisBaker2
      Qrew Member

      This method seems similar to the one I thought about writing with the JSON API where I think you could 

      1. create a relationship as usual, this will create a reference field in just the fields list
      2. use the JSON response on creation to get this new fields' id value
      3. use that field id and the update_field method to add the addToForm property to it and it gets added to the bottom

      I will take a look at the XML version and see what I can do.

      Thanks.



      ------------------------------
      Chris Baker
      ------------------------------
      • Gary1's avatar
        Gary1
        Qrew Assistant Captain

        With the XML API add_to_forms is only handled when a field is created. Nothing happens if you update the attribute after the initial field creation. Maybe the JSON API is different, but I'm doubtful.



        ------------------------------
        gary
        ------------------------------