Forum Discussion

KenCasser's avatar
KenCasser
Qrew Cadet
7 years ago

Syntax Question on API_AddRecord

In doing an API_AddRecord, I can get this to work:

"<field fid='18'>Hi!</field>";

and field 18 in the new record will contain the phrase "Hi!".

But how do I put the result from an equation (such as xyz=2+2) into field 18?  I've tried

"<field fid='18'>$xyz</field>";

$(xyz) and a jillion others, but can't crack the code.

Thank you!
  • Hi Ken,

    Would the math you are attempting to build into the API AddRecord be an equation based on fields in Quick Base or is this data coming from an outside source and being passed into QB? If it is an AddRecord from Quick Base to Quick Base the most reliable suggestion is to make a field that does that contains that formula and its results to be included in the API call. 
  • Hi Evan,

    No, it's not based on existing fields.  It uses javascript to concatenate parts of the date Today() into the format 180420 for example, and then adds two more characters which increment each time the equation is called.  i.e., the first of the day is 18042001, then 18042002, 18042003, etc.  And, it resets back to 01 at the end of the day so that tomorrow will start 18042101, 18042102...  My equation is xyz=(the variable result).  I know it works because after the </qdbapi> I have console.log(xyz), and the correct result prints to my console each time the api call is made.  I just can't figure out how to phrase the variable xyz so that 18042001 is put into the new record's field instead of the letters xyz.  No matter what I indicate as the value for fid 18, it prints it literally as xyz, not 18042001.  Thank you for helping!  I'm relatively new to QB & js and I appreciate the support.
  • So, I've gone simple and am just trying to get 2+2 to equal 4 in an API call but I can't do it.  For 2+2 it just renders 2+2 as the input.  Very weird.
  • I see questions here that are either never solved (like mine), or don't give the final answer, but I've found the answer to this so I'll post it here for others to maybe benefit from.  The solution is to put the variable outside of the quotes, i.e.:

    "<field fid='18'>"+xyz+"</field>";

    What a relief!
  • Hi Ken, I'm glad to hear you were able to find an answer to your question. It was a good one as I didn't know either, I don't build much with API calls for data not coming from native quick base. Was hoping one of the forums other users might be more familiar. Thank you for sharing the info.