Search code examples
ibm-mobilefirstjsonstore

Worklight 5.0.6 JSONStore with Sync error


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.


Solution

  • 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().