Discussions

Expand all | Collapse all

Conditional API_EditRecord Statement

  • 1.  Conditional API_EditRecord Statement

    Posted 06-15-2017 13:55
    I am new to xml so I'm having some trouble with a simple if-then statement in my API call.
    I want to say, If FieldA is not blank then edit fid 10 on the endpoint table to equal FieldA, else edit it to equal FieldB.  This is my latest attempt.

    <qdbapi>
    <usertoken>123456789</usertoken>
    <rid>34</rid>
    <if cond="[FieldA]!=''">
    <field fid='10'> [FieldA] </field>
    <else/>
    <field fid='10'> [FieldB] </field>
    </if>
    </qdbapi>

    Can anyone advise where I'm going wrong?


  • 2.  RE: Conditional API_EditRecord Statement

    Posted 06-15-2017 13:58
    I suggest that you create a native field which will do the "IF" in your app  and then just have the API use that calculated field.


  • 3.  RE: Conditional API_EditRecord Statement

    Posted 06-15-2017 14:33
    I have about 30 such conditions to check (60 fields in total).  In your experience, will this still be the best approach?


  • 4.  RE: Conditional API_EditRecord Statement

    Posted 06-15-2017 14:35
    :) since I don't do javascript and I don't know if XML can do an IF statement, that is how I would have to do it.   Someone else would have to chime in as it if XML can do an IF without resorting to a code page.


  • 5.  RE: Conditional API_EditRecord Statement

    Posted 06-16-2017 03:28
    I'm not a whiz with XML or Javascript either, but every time I have worked with my developer to have them code stuff to work for me in QuickBase, they have always had me do the formula or filtering or query decision logic directly in QB by creating formula checkbox fields for them first, and that way the code can be super simple and just pull records where the checkbox value for a single field is true. And if your business logic changes in the future, which it most likely will, you don't have to go rooting around in JS or XML code to find and update your logic.

    Look at it this way: you are human. What is easier for your eye to read at a glance? XML or JS or QB formulas? For me, it's the last one. I also have more control over it directly because I don't want to be a JS coder. I have a business to help run. Like Mark, I want to get it done cleanly and quickly myself, preferably in native QB whenever possible. So, do the logic as much as you can in native QB. That will keep the complexity down in your code as much as possible.