1
votes

I have a local jsonstore linked to a remote sql database through an adapter. I am trying to push local data to the remote database like this :

submit_data = function () {

    accessor.getPushRequired().then(function (result) { alert(result.length);

        accessor.push();

    });

Let us say I only added documents (no replace/remove). I want my add procedure to look like this:

function addGegegr(document) {

    //WL.Logger.warn(document[56]);
    return WL.Server.invokeSQLStoredProcedure({
        procedure : "DBO.USP_TIM_add_sp",
            parameters : [document.key1,document.key2,document.key3,...]
    });
}

And same for the replace/remove procedure, they should be calling other stored procedures with the same parameters.

However, I get errors because it seems the variable "document" worklight is passing to the add function after push is called is just a string and not a json object.

So my question is : how do I access the json attributes from the adapter procedure? If not possible, can I pass those attributes to the push function?

P.S.: passing each of the n documents to add as parameter of push() does not work and causes add to be called n*n times instead of n...

1

1 Answers

0
votes

Try using JSON.parse to turn the string into a JavaScript object.

function addGegegr(document) {
  var doc = JSON.parse(document);
  //... use doc as a regular JavaScript object
}

If JSON.parse is not available there, you can add it by including this code in the adapter implementation file.