Calculation Question: If field is NULL- do not show
Hey Guys!
Not much of a coder and I am trying to generate a UTM link (Google Analytics) in my calculation field by combining fields...and I would like to not display segments of the code when a field is blank.
Here's the code for my calculation field...
@Link + "?utm_campaign=" + @Campaign.replace(/ /g, '') + "&utm_source=" + @Source.replace(/ /g, '') + "&utm_medium=" + @Medium.replace(/ /g, '') + "&utm_content=" + @Content.replace(/ /g, '') + "&utm_term=" + @Term
What I mean by segment is each @field value is coupled with "&utm_fieldname" to render "&utm_fieldname=fieldvalue"
Any pointers?
-
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
-
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!
-
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>
Please sign in to leave a comment.
Comments
7 comments