Bob T
Bob T

Reputation: 75

WL.JSONStore.push does nothing

I'm using Worklight 6.2 to build a simple example of data sync using JSONStore and a SQL Adapter. Everything seems to be working the way I want, except for the "push" back to the adapter. My application pulls data via the "load()". I allow the user to select an item, change it, and then "replace()" inside the collection. However, when I call "push()", nothing happens. No errors - nada. I'm hoping this is a simple "typo" problem, but I'm stumped at this point.

Any input would be GREATLY appreciated!

-bob-

Things that are working:

WL.JSONStore.init(),
WL.JSONStore.load(),
WL.JSONStore.findAll(),
WL.JSONStore.find(),
WL.JSONStore.replace(),
WL.JSONStore.pushRequiredCount()

What's not working is the last and most important:

WL.JSONStore.push();

Here's my sync code:

function syncWithServer(){
// THIS FIRST PART WORKS - YAY!!!!!
console.log ("Check for dirty records");
WL.JSONStore.get(employeeCollectionName).pushRequiredCount()
.then(function (numberOfDirtyDocuments) {
    alert("DIRTY: " + numberOfDirtyDocuments);
 })

.fail(function (errorObject) {
    alert (errorObject);
});

 / NOTHING HAPPENS AFTER THE LOG  - JUST FALLS THRU TO THE LAST CONSOLE LOG
// NO ERRORS OR ANYTHING

console.log("Atempting to update server");

WL.JSONStore.get(employeeCollectionName).push()
 .then ( function (res) {
    alert("Server updated successfully");
})
 .fail ( function (errorObject){
    alert (errorObject);
});
console.log("HUmmmmmm .....");
}

Upvotes: 2

Views: 453

Answers (2)

Namfo
Namfo

Reputation: 301

I ran your test app from you GitHub account and I was able to run it fine using an HTTP adapter and the callbacks returning correctly. Which logs did you receive when using an SQL adapter, if any.

[EDIT ~ 8/6] I created an SQL adapter and was able to push and pull from the adapter.

Upvotes: 1

Daniel A. González
Daniel A. González

Reputation: 1225

Your application seems to be doing the right thing, so this could be a defect. However, the push() and load() API are deprecated as of 6.2, and I think that if you follow the new approach it will work for you.

The new approach is to call the adapter directly; this is all that JSONStore did anyways when you called push() or load(), while constraining you to what parameters you can send to it, so it makes more sense that you call the adapter directly. For push, you can edit your push call like this:

WL.JSONStore.get(employeeCollectionName).getAllDirty()

.then(function (dirtyDocs) {

  return WL.Client.invokeProcedure({
    adapter : 'people',
    procedure : 'updatePeople',
    parameters : [ dirtyDocs ]
  });
})

.then(function (responseFromAdapter) {
  // ... call markClean API after a valid response form the adapter
});

Making sure to change the parameters and procedure and adapter name to your adapter's.

Also, this answer is a very short summary of what is in the documentation for working with external data, including examples on how to do push and pull (load).

That said, even though push() and load() are deprecated, they should still work, so a defect has been created to look further into this.

Upvotes: 2

Related Questions