How to show one field in a calculation, and another if it is blank (IF / THEN)
Apologies as I am very new to this. I am trying to get show a calculation to work so it will show a code for a project when it is populated, but if it is empty, show another field (the full title).
It is part of a larger series where I show a type of report, the project code or title it is connected to, and the date it is due. I tried this, any ideas what I can change to make it work? Sorry I am sure this is simple
var code1 = @All of Contract code !=null ? code1: @All of Title;
@Report type + " | " + code1 + " | "+ moment(@Due date).format("DD/MM/YYYY");
-
HI Jeremy,
it must be: @All of Contract Code != "" - not != null.
If you want to check a field in the same item if it is not empty you must use != null (@Contract Code != null)
But it you want to check it in a related item that you reference with @All of fieldname it's !=""
The call @All of fieldname returns an array [], it doesn't matter if you pull the field value from one item or multiple items. Example:
A) Only one item related: @All of code returns ["Code A"] - one element in the array - not empty
B) Multiple items related: returns ["Code A","Code B","Code C"] - three elements in the array - not empty.
C) No item related: [] - empty array.
And wether an array is empty or has elements: if array == "" or if array != ""Rainer
-
Hi Rainer,
Thanks very much for your support! I was struggling a bit to make this work but your advice around !=null and !="" really helped.
I managed to get the issue fixed with the below:var grantcode1 = @All of Contract code
if(@All of Contract code!= ""){
grantcode1 = @All of Contract code;
}
else{
grantcode1 = @All of Title
}
@Report type + " | " + grantcode1 + " | "+ moment(@Due date).format("DD/MM/YYYY");
Really appreciate it!
Jeremy
Please sign in to leave a comment.
Comments
2 comments