API_ImportFromCSV", using key fiel of the table ecord ID# (Record ID#) Field ID: 3 is not performing Update

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered

I use intensively Dan’s Diebolt ImportCsv Technique (old fashioned, cause the Scooby doo, and Gimme All The Datas are the top stars now)

 

Have been trying sync csv, that feels good, but as I usually have to perform transformations before importing, I don’t know how to leverage from that feature until now.

 

For me is very important to clearly differentiate when to UPDATE or ADD a new record.

I spend a lot of time figuring unique keys, from different pieces of data.

 

Here is my problem (and I am sure the answer is very simple):

 

Have not been able to make work the:

 

var promise5 = $.post(dbidExtractos, {

          act: "API_ImportFromCSV",

          records_csv: csv_data_sem,

          clist: "3.7"

        });

 

When one of the clist is the Key record of the table #Record Id, in this case.

 

This setting should perform an update, but I don’t now why it does not.

 

 

This would simplify a lot my imports that appear as a Christmas tree, with lots of nested promises (sure that Dan would transform 22 nested promises or more into one line of code but...that’s what I have)

 

My setting to avoid this problem, case is something not so simple,

 

1.- created a shadow Table

 

2.- I import the data to the shadow Table.. In this importation I generate the unique export ID.

var promise1 = $.post(shadowEx, {

      act: "API_ImportFromCSV",

      records_csv: csv_data,

      clist: "6.15.7.9.14.8.10.11"

    });

 

1 Promise

 

2.- I created  an import from the shadow Table to the actual Table, with a merge key

 

var promise5 = $.post(dbidExtractos, {

              act: "API_RunImport",

              id: 10

          });

2 Promises

 

3.- I purge the records of the Shadow table o keep it clean for next operation.

 

var promise6 = $.post(shadowEx, {

            act: "API_PurgeRecords",

            qid: 1

          });

3 Promises.

 

It Works nicely but something I could do with just one promise I use 3.

 

Any Hints

Photo of eduardo

eduardo

  • 40 Points

Posted 3 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
>Here is my problem (and I am sure the answer is very simple)

Always log the XML response using console.dirxml() to debug:

$.post(dbidTable, {
  act: "API_ImportFromCSV",
  records_csv: "1,alpha,john\n2,beta,jane",
  clist: "3.6.7"
}).then(function(xml) {
  console.dirxml(xml);
});

<errdetail>You cannot include the record ID if it is not the key field.</errdetail>


>This would simplify a lot my imports that appear as a Christmas tree, with lots of nested promises (sure that Dan would transform 22 nested promises or more into one line of code but...that’s what I have)

Those variables named "promise*" are just temporary variables - you can eliminate them by realizing that AJAX calls return a promise and therefor have a then method (they are called "thenable"):

So instead of this:

var promise = $.post( /* arguments */ );
$.when(promise).then(function(response) {
  // some code
});

or this:

var promise = $.post( /* arguments */ );
promise.then(function(response) {
  // some code
});


use this:

$.post( /* arguments */ )
  .then(function(response) {
    // some code
  });

If you always return a promise from your code you can chain them together with then() methods and avoid the "pyramid of doom" or "Christmas tree" indentation.

> ... Gimme All The Datas are the top stars now ...

Well I have an even better technique in the works called submitmeAllTheForms() which offers a complete automation of any QuickBase feature. I just need to get it down to a dozen lines of code and play with the parameterization.