Discussions

Expand all | Collapse all

API_AddRecord from JavaScript Array creating duplicates

  • 1.  API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:02
    Hello,

    I am using Javascript to pull out a row from one table, remove duplicates, and then I want to upload those results into another table, one record for each value.

    Distinct is the array, and it has the proper values. The issue I'm having is that it appears to be that the for loop is going through the values twice, as when I'm expecting 2 rows, I'm getting 4.

            Distinct.forEach(function(entry){
                 for(index = 0, len = Distinct.length; index < len; ++index){
                      var xhttp = new XMLHttpRequest();
                      xhttp.open('POST', "[REALM]/db/[DBID]?a=API_AddRecord&[TOKEN]&_fid_6="+Distinct[index],true);
                     xhttp.send();
                 }
            })

    I know that I'm probably overlooking something simple, like somehow closing the request, or trying to open it more than once...


  • 2.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:25
    Try this:

    var dbid = "your application dbid";
    var dbidTable = "your table dbid"
    var apptoken = "your application token";
    $.ajaxSetup({data: {apptoken: apptoken}});

    var distinct = ["foo", "bar", 'baz"];
    var csv = distinct.join("\n");

    $.post(dbidTable,{
      act: "API_ImportFromCSV",
      records_csv: csv,
      clist: "6"
    });


  • 3.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:30
    Dude... I was thinking the API_ImportFromCSV was going to be a lot more difficult than that... I'll check this out now.


  • 4.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:39
    It's erroring out stating that "Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."

    I believe that this is actually because I'm currently working from a local .html file on my desktop prior to moving this into the QB environment.


  • 5.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:45
    Paste your code into the console to test it.


  • 6.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 15:54
    Still not liking it. When I paste it into Codepen.io to test, it's now showing a 404 error when trying to perform the upload csv api


  • 7.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 16:00
    Paste the code into the console of your browser while on your QuickBase page. Codepen is on another domain so the relative URL dbidTable in the $.post() method will result in a 404 error.


  • 8.  RE: API_AddRecord from JavaScript Array creating duplicates

    Posted 09-06-2018 16:09
    That did it... for some reason I got hungup on the dbid vs dbidTable as well.

    Now to just turn this into a codepage and still have it work.