Conditional API_EditRecord Statement

  • 1
  • 1
  • Question
  • Updated 2 years 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.

<if cond="[FieldA]!=''">
<field fid='10'> [FieldA] </field>
<field fid='10'> [FieldB] </field>

Can anyone advise where I'm going wrong?
Photo of Richard Pfister

Richard Pfister

  • 584 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
  • 1
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

  • 584 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?
:) 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,216 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.