cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
UserID16644
Level V

How to get variable value inside IF Condition

Hi all,

I am stucked in this IF Condition, where I need to get the variable value(color) based on another column value (:Fruit). It always return an empty variable color. Please help

 

 

Here's my sample code: 

If( :Fruit == "Apple",
color= "Red"; Target = {50};,
:Fruit == "Grapes",
color= "Violet"; Target = {50};,
:Fruit == "Cherry",
color= "Red"; Target = {54};
);
1 ACCEPTED SOLUTION

Accepted Solutions
Thierry_S
Super User

Re: How to get variable value inside IF Condition

Hi,

 

It is unclear what you are trying to do given the limited context. Is this part of a JSL script or a column Formula? If it is the latter, you need to specify what the expression returns as shown below:

If(
	:Fruit == "Apple",
		color = "Red";
		Target = {50};,
	:Fruit == "Grapes",
		color = "Violet";
		Target = {50};,
	:Fruit == "Cherry",
		color = "Red";
		Target = {54};
);
color;

Also,  are you sure that the column's content :Fruit matches precisely the values in your expression (i.e., no leading or trailing spaces)?

An example of the usage context for this expression would help figure out what may be going on.

Best,

TS 

Thierry R. Sornasse

View solution in original post

2 REPLIES 2
Thierry_S
Super User

Re: How to get variable value inside IF Condition

Hi,

 

It is unclear what you are trying to do given the limited context. Is this part of a JSL script or a column Formula? If it is the latter, you need to specify what the expression returns as shown below:

If(
	:Fruit == "Apple",
		color = "Red";
		Target = {50};,
	:Fruit == "Grapes",
		color = "Violet";
		Target = {50};,
	:Fruit == "Cherry",
		color = "Red";
		Target = {54};
);
color;

Also,  are you sure that the column's content :Fruit matches precisely the values in your expression (i.e., no leading or trailing spaces)?

An example of the usage context for this expression would help figure out what may be going on.

Best,

TS 

Thierry R. Sornasse

Re: How to get variable value inside IF Condition

You might consider the more specialized conditional function Match(). It is a nice alternative that is perhaps clearer as far as the intent and the result

 

Match( :Fruit,
	"Apple",
		color = "Red";
		Target = {50};,
	"Grapes",
		color = "Violet";
		Target = {50};,
	"Cherry",
		color = "Red";
		Target = {54};
);