Conditional API_EditRecord Statement

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
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?
Photo of Richard Pfister

Richard Pfister

  • 554 Points 500 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,306 Points 50k badge 2x thumb
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.
Photo of Richard Pfister

Richard Pfister

  • 554 Points 500 badge 2x thumb
I have about 30 such conditions to check (60 fields in total).  In your experience, will this still be the best approach?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,306 Points 50k badge 2x thumb
:) 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.
Photo of Michael Barrow

Michael Barrow

  • 2,206 Points 2k badge 2x thumb
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.