Why does my snippet return a blank value for a field, rather than null or undefined?

  • 1
  • Question
  • Updated 4 years ago
So I'm providing a method for users to set criteria, and then I use a snippet to apply those criteria to another model which is then queried.

Here's the first part of the snippet:

var $ = skuid.$,    
    //get the models from the page
    search = skuid.model.getModel('SearchCriteria');
    operatorsModel = skuid.model.getModel('SearchOperators');
    typeModel = skuid.model.getModel('SearchCATG');
    //get the first row which contains the criteria which we will use to set model conditions
    var criteria = search.getFirstRow();
        //get the values of fields in that first row
        var paxCount = search.getFieldValue(criteria,'PAX__c',true);
                console.log("PAX Count is " + paxCount);
                // this is an integer/double field and returns null or undefined if I run it without a value
                // if I run it with a value first, and then try to run it again without a value, it returns a blank value
                // ie not null or undefined, just empty.
        var cargo = search.getFieldValue(criteria,'Cargo__c');
                console.log("Cargo is " + cargo);   
                // this is a boolean and always returns true or false

the variable paxCount is the one I'm having issues with. If the user puts a value in the first time, e.g. 7 and executes the search, it all works fine. But if the user then deletes the value of that field in the UI (this field is 'PAX__c'), I would expect that the variable paxCount would return a value of either null or undefined. But it's not, it's just returning a blank value, and my model condition still thinks it has something in it.

This is the part of the snippet where I try to set the value of the condition using paxCount, or I try to deactivate the condition if it is null or undefined:

    //set the conditions on the Operators Model, from the values contained by search criteria    var minPAX = operatorsModel.getConditionByName('minPAX',true);
        if (paxCount !== null || undefined) {
            console.log("Activated minPAX");
        } else {
            console.log("Deactivated minPAX");

Any ideas as to why I'm getting an empty/blank value, when my expectation is that it should be null or undefined???
Photo of Greg Jarrett

Greg Jarrett

  • 3,526 Points 3k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Greg Jarrett

Greg Jarrett

  • 3,526 Points 3k badge 2x thumb
so I managed to solve this one this morning with something that seems pretty obvious in hindsight. Essentially the condition was just returning an empty string, so I just created a condition to check for that, and if true, then set it to null instead:

var paxCount = search.getFieldValue(criteria,'PAX__c');
  if (paxCount === "") {
    paxCount = null;
//do a bunch of other stuff
console.log("PAX Count is " + paxCount);

seems simple looking at it now...grrrr.