Expand my Community achievements bar.

SOLVED

JavaScript with OR statement syntax

Avatar

Level 2

I am trying to setup some code that will look at a value in one field, and based on the result it finds determine what translated. I can get this to work when I have a single entry (for example "AB"), but when I try to expand this with an OR statement I no longer can get it work. It seems to just take the first entry, and stop there. I have tried different variations, and I have not been able to get it to go. I also tried to options with Formcalc. Does anyone happen to know what is incorrect in the syntax. If you have another suggestion with Formcalc I am OK with that as well.

 

if ( $record.PAGE.FIELD.value == "AB" || "CD" || "EF" || "GH" || "IJ")

        {

        this.rawValue = (data.PRINTLANG.rawValue == "EN") ? "Product" : "Produkt";              

        }else{

        this.rawValue = (data.PRINTLANG.rawValue == "EN") ? "Service" : "Dienstleistung";

        }

Thanks,

Andrew

1 Accepted Solution

Avatar

Correct answer by
Level 7

I would modify to be:

if ($record.PAGE.FIELD.value == "AB" || $record.PAGE.FIELD.value == "CD" || $record.PAGE.FIELD.value == "EF" || $record.PAGE.FIELD.value == "GH" || $record.PAGE.FIELD.value == "IJ")

You could simplify it to be:

var a = $record.PAGE.FIELD.value

if (a == "AB" || a == "CD" || a == "EF" || a == "GH" || a == "IJ"){

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

I would modify to be:

if ($record.PAGE.FIELD.value == "AB" || $record.PAGE.FIELD.value == "CD" || $record.PAGE.FIELD.value == "EF" || $record.PAGE.FIELD.value == "GH" || $record.PAGE.FIELD.value == "IJ")

You could simplify it to be:

var a = $record.PAGE.FIELD.value

if (a == "AB" || a == "CD" || a == "EF" || a == "GH" || a == "IJ"){

Avatar

Level 2

I used your formatting, and adjusted the first line of my code to the following,

if (( $record.PAGE.FIELD.value == "AB") || ($record.PAGE.FIELD.value "CD") ||

($record.PAGE.FIELD.value "EF") || ($record.PAGE.FIELD.value "GH") || ($record.PAGE.FIELD.value "IJ"))

This made it work. I appreciate the help.