Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RestDataSource.transformRequest() sets dsRequest.data to null

    In the example in the docs: https://smartclient.com/smartclient-...ansformRequest

    ... shows this:


    Code:
       transformRequest : function (dsRequest) {
           // modify dsRequest.data here, for example, add fixed criteria
           dsRequest.data.userId = myApplication.getCurrentUserId();
    
           return this.Super("transformRequest", arguments);
        }
    This used to work in older versions, now it does not.
    Because dsRequest.data is getting set to null, where it used to enter this function as an empty (but existing) object.

    The workaround for now is to do something like this:
    Code:
       transformRequest : function (dsRequest) {
            // modify dsRequest.data here, for example, add fixed criteria
    
            if (!dsRequest.data) {
                dsRequest.data = {};
            }
    
           dsRequest.data.userId = myApplication.getCurrentUserId();
    
           return this.Super("transformRequest", arguments);
        }
    I compared old code to new, stepped through it, and found where it's different:

    Old, in ISC_DataBinding.js (line 56611-ish in debug version of js file):
    Code:
        getServerFilter : function () {
            ....
            return isc.shallowClone(this.criteria);  // This just returns an empty object (if this.criteria is an empty object)
        },
    New, in ISC_DataBinding.js (line 57819-ish in debug version of js file):
    Code:
        getServerFilter : function () {
            ....
            return this.getCombinedCriteria();  // This returns null if this.criteria is an empty object
        },
    This happens down in ISC_DataBinding.js (line 38025-ish in debug version of js file):
    Code:
    compressNestedCriteria : function (criteria, outerOp, isSubCrit) {
            // this method will take a nested criteria object and reduce it (like flattenCriteria(),
            // but its not all or nothing) to its simplest format (like simplifyAdvancedCriteria(),
            // but without installing extra outer adv-crit or flagging single criterions as advanced)
    
            if (!criteria || isc.isAn.emptyObject(criteria)) return null; // This is where it happens! If criteria is empty, it returns null!!!
            ....
    Cheers!
    ECDragon

    #2

    dsRequest.data can validly be null, and also, note that your code won't work if AdvancedCriteria is passed.

    However, there's no reason why our code should be transforming criteria specified as an empty object to a null (even if that's equivalent), so we've fixed that.

    You will see this fix as of tomorrow's builds, Apr 29.

    Regards
    Isomorphic Software

    Comment

    Working...
    X