ibm-mobilefirstjsonstore

JSONStrore / WORKLIGHT


One little problem which JSONStore.add(data).then().fail()

The function initialiserBD() runs and returns success. The function remplireBD() doesn't return success. Surely, it is the function WL.JSONStore.get().add().then().fail()

Object "errorObject" send error :-50 PERSISTENT_STORE_NOT_OPEN

function wlCommonInit() {
   initialiserBD();
   remplireBD();
}

function initialiserBD() {
    var collectionName="Personnes" ;
    var collections = {};

    collections[collectionName]= {};
    collections[collectionName].searchFields={nom :'string'};

    WL.JSONStore.init(collections).then(function(){})
        .fail(function(errorObject) {
            alert(errorObject.tostring());
        });
}

function remplireBD(){
    var data = {
        nom :'Bill Gates'
    };
    var collectionName = 'Personnes';

    WL.JSONStore.get(collectionName).add(data).then(function () {})
        .fail(function (errorObject) {
            alert(errorObject.toString());
        });
}


Solution

  • I think your problem is two-fold...

    1. You initialize the collection both before init and "after" init (var collectionName="Personnes" ;)
    2. JavaScript is async, and you're calling initialiserBD and remplireBD one after the other instead of calling remplireBD in the success callback of initialiserBD, which could lead to trying to .get() before init() completed...