PDA

View Full Version : Need help!


Craig
April 18th, 2012, 12:17 PM
I am trying to create a rule that will compare 2 fields and if both fields exist, a bullet will be returned between them. If only one field exists there is no bullet. Here is where I am at...

if (Field("2nd Email")&&(Field("Cottage Name"))
return NormalizeEntities(Field("2nd Email")) " • " + NormalizeEntities(Field("Cottage Name"));
//else
return "" + NormalizeEntities(Field("Cottage Name"));


So my outcome would be
bob@abc.com • Bobs House
or
bob@abc.com
or
Bobs House

Any help would be GREATLY appreciated

step
April 18th, 2012, 12:42 PM
You could write it the way you have with if/else statements:

var result = "";
if (Field("2nd Email") != "" && Field("Cottage Name") != ""){
result = NormalizeEntities(Field("2nd Email")) " • " + NormalizeEntities(Field("Cottage Name"));
}
else if (Field("2nd Email") != ""){
result = NormalizeEntities(Field("2nd Email"));
}
else if (Field("Cottage Name") != ""){
result = NormalizeEntities(Field("Cottage Name"));
}

return result;


or you could simplify the code by using an array:

var s = NormalizeEntities(Field("2nd Email"));
var f = NormalizeEntities(Field("Cottage Name"))";
var result = [];
(s != "") ? result.push(s) : "" ;
(f != "") ? result.push(f) : "" ;

return result.join(" • ");

Craig
April 18th, 2012, 12:46 PM
Thanks! Guess I looked like a boob!