Skip to main content
Question

Trying to pass a value derived from javascript code to a field in quickbase

  • April 17, 2018
  • 0 replies
  • 201 views

I've written a lovely piece of javascript which creates a unique quote number and resets every night, but I can't figure out how to pass that value from my javascript file (which is a code page in quickbase) to a field in my quotations table.  When generating a New Quote, I want quickbase to take the Quote Number from the javascript file and insert it into the Quote # field.  Can someone point me in the right direction?  I could get the javascript result to print on a blank browser page, and got it to print in the console.log(), but that's it.  Thank you!
This topic has been closed for replies.

  • Quickbase Alumni
  • April 17, 2018
Can you embed the js in a HTML form element with a name="_FID_##" ?

  • Quickbase Alumni
  • April 17, 2018
The easiest would be as Chris suggested and simply use a hidden form to submit with API_AddRecord or you can use an AJAX post method to do the same.  To find the field ids to reference you can look at the fields in your QB and, if I remember correctly, you can find an advanced button and have it show you the field ids in the listing as well. 

Once you do that, you'll be able to find your field ids to associate correctly and use a form or the api to add the record.

https://help.quickbase.com/api-guide/index.html#add_record.html%3FTocPath%3DQuick%2520Base%2520API%2...

  • Author
  • Quickbase Alumni
  • April 17, 2018
Thank you both for your help!

Chris - I can "embed the js in a HTML", but I don't yet exactly know what a "form element" is.  I'm presuming you're not referring to renaming the code page I created, but putting the HTML in its own Field named "_FID_##" (without the quotes, and with the field number of the place where I want the result to appear as ##).  But, that can't be.  If I paste my HTML file with the js imbeded in it to a Formula - Rich Text field, I get stopped at every line.  so I guess I don't know where the "form element"s are.

Brett - I guess you are saying I need to create my own button to do an API_AddRecord rather than use the native "+New Quote" green button that is on my page, which is fine if I can figure out a) how to do it, and b) how to get rid of the "+New Quote" green button so our people don't get confused.  I don't know anything about "AJAX", but I'll look into it, and I'll read up on where an API_AddRecord gets its data.  I think I know how to get the field ids (Advanced Options button in 'Settings, Fields').

So, I'll muddle through this today and hope I come up with the right moves!  I appreciate your help.

Ken

  • Quickbase Alumni
  • April 17, 2018
Ah, based on that reply it sounds like the JS that you added is in QB itself rather than in an external website, correct?  If that's the case, it's probably best to relate the tables and use something native in the QB to create the new records in your separate table.

  • Author
  • Quickbase Alumni
  • April 17, 2018
Correct.  It's just a file I wrote that I thought would work as a formula but it's getting to be quite a bit more involved than that.

  • Quickbase Alumni
  • April 17, 2018
I assume from all the comments that your "lovely piece of javascript" is loaded into a edit or add record page. From this point there are two ways to "pass that value from my javascript file (which is a code page in quickbase) to a field in my quotations table."

(1) Set Field Value Via Form Field

_fid_6.value = calculated_value;

(2) Set Field Value Via API
$(dbidTable, {
  act: "API_EditRecord",
  rid: kRid,
  _fid_6: calculated_value
});

  • Author
  • Quickbase Alumni
  • April 17, 2018
The choices of Pages were Home Page, Rich Text Page and Code Page.  Not "edit or add record page".  As I said, I'm missing something very basic.  I have tables with fields, forms and pages, but I can't figure out where the code goes...

  • Author
  • Quickbase Alumni
  • April 20, 2018
When I copied my code above, it missed the last line which gave the result.  It should have ended with:

q=(yr+leadingZero(mo)+leadingZero(da)+leadingZero(a));

In the meantime, I've figured out how to access my javascript page with a URL button, and am doing an API_AddRecord using ajax (modified from the QB API Boot Camp).  I've successfully generated new records and am able to pass literals using:

  var request="<qdbapi>";
  request += " <field fid='7'>Kenny</field>";
  request += "<field fid='6'>q</field>";
  request += "</qdbapi>";

Field 7 says "Kenny", and field 6 says "q".  I want field 6 to have the result of the variable.  I've tried:

request += "<field fid='6'>$q</field>";

and a bunch of other iterations, and I've searched and read and searched and read, but can't for the life of me figure out how to get the value of q into fid 6.  (Yup, I tried value.q, value(q), etc)

I also tried adding:

$(bnfynvsjt, {
  act: "API_EditRecord",
  rid: kRid,
  _fid_6:q
});

to it, but that didn't work either.  Maybe I put it in the wrong place or maybe I can't do two API calls in the same script, but I can play with that some more tomorrow.  But if you can save me some time I'd sure appreciate it!

Oh, and I know the calculation is working because after the 'request' info I do a console.log(q), and a correct result appears in the console when a new record is generated.

Any ideas?  Thank you!

  • Author
  • Quickbase Alumni
  • April 22, 2018
In case you're wondering...the answer is:

request += "<field fid='6'>"+q+"</field>";