Skip to main content
Aurélien Laval a posé une question dans #Mobile
Hello, I develop en an Android application with the Salesforce Mobile SDK to store datas offline in using smartstore.

 

I saw the Mobile SDK Workbook but it's not said how store manually datas with smartstore.

 

Per example, I want when a user populate a form and submit it, store form's informations in the mobile with smartstore and I don't how do it.

 

In this time, I tried this :

 

function Track(){

 

    this.Id = null;

 

    this.Name = null;

 

    this.Price__c = null;

 

    this.Album__c = null;

 

    this.Album__r = null;

 

}

 

function Album(){

 

    this.Id = null;

 

    this.Name = null;

 

}

 

var track = new Track();

 

track.Id = $j('#.idInput').val();

 

track.Name = $j('#.nameInput').val();

 

track.Price__c = $j('#.priceInput').val();

 

track.Album__c = $j('#.albumIdInput').val();

 

track.Album__r = new Album();

 

track.Album__r.Id = $j('#.albumIdInput').val();

 

track.Album__r.Name = "A name";

 

var myTable = [];

 

myTable.push(track);

 

addOfflineTracks(JSON.stringify(myTable), successAdd, errorAdd);

 

I get an error :

 

http://nsa33.casimages.com/img/2013/08/12/130812124002327909.png

 

I guess than I don't give the good datas to store with smartstore because when datas are loaded from a Salesforce controller, a list is given to store and I use a table.

 

How can I use a list en Javascript please?

 

Sorry if I use a bad language.
4 réponses
  1. 12 août 2013, 15:51
    I have an issue for my problem, this my code :

     

    var indexesTracks = [

     

      {path:"Name",type:"string"},

     

      {path:"Id",type:"string"},

     

      {path:"Album__c",type:"string"}

     

    ];

     

    smartStore.registerSoup(TRACKS_SOUP_NAME, indexesTracks, onSuccessRegSoup, onErrorRegSoup);

     

    function hasSmartstore() {

     

       var smartStoreDefined = false;

     

       if (cordova && cordova.require) {

     

           var smartStore = cordova.require("salesforce/plugin/smartstore");

     

           if ((typeof smartStore !== "undefined") && (smartStore !== null)) {

     

               console.log("SmartStore plugin found and loaded");

     

               smartStoreDefined = true;

     

           }

     

       }

     

       

     

       return smartStoreDefined;

     

    }

     

    function addOfflineTracks(entries, success, error) {

     

      if (hasSmartstore()) {

     

         var smartStore = cordova.require("salesforce/plugin/smartstore");

     

         smartStore.upsertSoupEntries(TRACKS_SOUP_NAME,entries, success, error);

     

      }

     

    }

     

    var trackJSON = [{

     

      "Name" : "Name",

     

      "Id" : "Id",

     

      "Album__c" : "1234567890123456"

     

    }];

     

    var successAdd = function(message){

     

      alert("Great : " + JSON.stringify(message));

     

      console.log(JSON.stringify(message));

     

    }

     

                   

     

    var errorAdd = function(error){

     

     alert("Pas bon : " + JSON.stringify(error));

     

     console.log(error);

     

    }

     

    addOfflineTracks(trackJSON, successAdd, errorAdd);
0/9000