Calculation Question: If field is NULL- do not show

Comments

7 comments

  • Rainer Grabowski

    Hi Ryan,

     you can do this: 

    var campaign = @campaign != "" ? "utm_campaign=" + @campaign.replace(/ /g,"") : "";
    var source = @source != "" ? "&utm_source=" + @source.replace(/ /g,"") : "";

    var url = @link + "?" + campaign + source;
    url.replace("?&","?")

    Create a var for each field. If != "" doesn't work try != null (depends on the field type). 

    Rainer

    1
    Comment actions Permalink
  • Ryan Vickerman

    @Rainer...you are AWESOME! Thank you!!!

    0
    Comment actions Permalink
  • Michal Novak

    Hi Guys,

    What you have done here is exactly what I need but I cannot work it out from the example.

    My scenario is very simple, just three fields combined together into one string, which will not display the NULs.

    @Unique ID + "-" +@All of Nick Name+ "," + @Car Required

    Thanks a lot!

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Michal,

    there are several ways to achieve it, one is: 

    var name = @All of Nick Name;
    var name = name != "" ? name.toString() : "";
    var car = @Car Required;
    var car = car != null ? "," + car : "";
    (@Unique ID + "-" + name + car).replace("-,","-")

    Rainer

    0
    Comment actions Permalink
  • Michal Novak

    Thank you very much Rainer!

    0
    Comment actions Permalink
  • Hugo Breda

    Hi Rainer,

    When i do this with a money field, the result it a little messy.
    I have tried with '== undefined ' or ' == null'...with '=' or '=='...
    I can't get the null value here...even if the money field is empty.

    <code>

    var _display = "";
    var _lim = @All of money field with nulls;
    _lim = _lim[_lim.length-1];


    if(_lim = ""){
    _display = "# " + "0";
    }
    else{
    _display = "# " + "$" + _lim.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
    }

    _display

    </code>

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Hugo,

    you've a typo. Must be

    if(_lim == ""){

    double ==, not single = in IFs

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk