1

I try to init JSONStore Sync with Adapter in Worklight 5.0.6 like below:

           var usersSearchFields = {"age":"integer","name.demo":"string"},
                usersAdapterOptions = {
                    name: 'user',
                    replace: 'updateUser',
                    remove: 'deleteUser',
                    add: 'addUser',
                    load: {
                        procedure: 'getUsers',
                        params: [],
                        key: 'users'
                    },
                    accept: function (data) {
                        return (data.status === 200);
                    }
                };
                var collections = {
                        users : {
                        searchFields : usersSearchFields,
                        adapter :   usersAdapterOptions
                        }
                };
                var options = {
                        username: 'carlos', 
                        password: '123' 
                        };
                var usersCollection=WL.JSONStore.init(collections, options)
                        .then(function (res) {
                            logMessage('Collection has been initialized');      
                        })  
                        .fail(function (errobject) {
                        WL.Logger.debug(errobject.toString());
                        });

It runs successfully in the first time but after i exit app then return, it gets error: *"PROVISION_TABLE_SEARCH_FIELDS_MISMATCH"*

Anyone can help me please? Thank you very much.

HoangNguyen
  • 183
  • 2
  • 9

1 Answers1

2

It looks like the following known issue:

PM85364: JSONSTORE ERROR AFTER FIRST LAUNCH ON ANDROID WITH '.' IN SEARCH FIELDS.. To fix it upgrade to the 5.0.6.1 Fix Pack (Source).

Typically:

-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH

You cannot change search fields without calling destroy or removeCollection and init or initCollection with the new search fields. This error can happen if you change the name or type of the search field. For example: {key: 'string'} to {key: 'number'} or {myKey: 'string'} to {theKey: 'string'}.

The documentation is here. I also recommend this StackOverflow answer on JSONStore debugging.

This fixes issues like the one you're facing:

Reset the Simulator or Emulator and/or call WL.JSONStore.destroy().

Community
  • 1
  • 1
cnandreu
  • 5,113
  • 3
  • 25
  • 50
  • but i didn't change search field value, just exit app and return, i realize that if i change search field **{"name.demo":"string"}** to **{"name":"string"}**, it wont't get this error, but "name.demo" is what i want – HoangNguyen May 23 '13 at 05:04
  • Your issue is explained in my answer above, specifically when I said *"or {myKey: 'string'} to {theKey: 'string'}"*. Notice "myKey" changed to "theKey". A solution was also provided in my answer above. Search fields are not dynamic and you are treating them as such. – cnandreu May 23 '13 at 06:54
  • Hi, I guess you miss understood me. it is about naming convension of Json Store's keys. When I use name without "." for example: "name", everything is fine. However, when I use "." in the key's name for example:"name.demo", then, in the first time using application, it is fine. However, when I close my application, re-open it again I received this error message and cannot proceed with JSon store search. Notice that i always destroy jsonstore before change searchfield's name to test. – HoangNguyen May 27 '13 at 03:18
  • Sorry about that, I did miss understood your message. Seems like you're running into this issue: [PM85364: JSONSTORE ERROR AFTER FIRST LAUNCH ON ANDROID WITH '.' IN SEARCH FIELDS.](http://www-01.ibm.com/support/docview.wss?rs=180&uid=swg1PM85364) Try installing 'Fix Pack 5.0.6.1' ([source](http://www-01.ibm.com/support/docview.wss?uid=swg27038650#5061)). – cnandreu May 27 '13 at 05:59
  • Updated answer to link to the issue. – cnandreu May 27 '13 at 06:01
  • 1
    thanks cnandreu, i have updated to worklight 5.0.6.1 and fixed this error! – HoangNguyen May 29 '13 at 18:24