ibm-mobilefirstjsonstore

WL JSONStore Sort key <field> is not one of the valid strings


I am having an error when trying to sort doing a findAll:

"Sort key dateis not one of the valid strings."

My options are the following (I tried different formats for desc, everyone was throwing the same 'error'):

var options = {sort: [{"date": "desc"}]};

Everything seems fine, the JSONStore works as expected, sorting the returned data, I just want to be sure that the 'error' is indeed a bug or mistake on the worklight.js part and not that I am doing something wrong.

This is the function that checks for a valid sortObj in worklight.js:

  /** Checks if sortObj is a valid sort object for a query
   *   @private
   */
  var __isValidSortObject = function(sortObj, searchFields, additionalSearchFields) {
    var propertiesValidated = 0,
    sortObjKey, sortStr;

    for (sortObjKey in sortObj) {
      if (sortObj.hasOwnProperty(sortObjKey)) {
        if (propertiesValidated > 0) {
          WL.Logger.trace('Sort object ' + JSON.stringify(sortObj) + ' has more than one property. Each object must have only one property.');
          return false;
        }

        //check is sortObjKey is lowerCase
       if (_.isUndefined(searchFields[sortObjKey.toLowerCase()]) && _.isUndefined(additionalSearchFields[sortObjKey.toLowerCase()])) {
          WL.Logger.trace('Sort key ' + sortObjKey + ' is not part of search fields: ' + JSON.stringify(searchFields) + ' or additional search fields: ' + JSON.stringify(additionalSearchFields));
          return false;
       }

       sortStr = sortObj[sortObjKey];

       //Check that the string that specifies sorting order says either "asc" or "desc"
       **if (__isString(sortStr) && sortStr.length > 0 && (/^(a|de)sc$/i.test(sortStr))) {
          WL.Logger.trace('Sort key ' + sortObjKey + 'is not one of the valid strings.');
          propertiesValidated++;
       } else {  
          // Here seems to be the problem, shouldn't the trace be before return false?
          return false;
       }**
      }
    }

    if (propertiesValidated === 0) {
      return false;
    }

    return true;
 };

You can clearly see that they do the WL.Logger.trace when the check is fine and that it should be just before return false.

Does anyone that has used sort on a JSONStore receives this trace as well?.

Platform version: 7.1.0.00.20160129-1923


Solution

  • I contacted IBM support and they indeed confirmed that it is a bug that will be solved in the next build.