Skip to main content
Question

API_AddRecord from JavaScript Array creating duplicates

  • September 6, 2018
  • 0 replies
  • 65 views

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...

  • Registered
  • September 6, 2018
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"
});

  • Author
  • Registered
  • September 6, 2018
Dude... I was thinking the API_ImportFromCSV was going to be a lot more difficult than that... I'll check this out now.

  • Author
  • Registered
  • September 6, 2018
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.