I have the following within the dynamic expression of an ADF IF Condition:
#if(equals(variables('V_D_MAX_LOAD_ID_HIS'), ''), true, equals(variables('V_D_MAX_LOAD_ID'), variables('V_D_MAX_LOAD_ID_HIS')))
3 Cases can occur:
V_D_MAX_LOAD_ID_HIS is NULL and V_D_MAX_LOAD_ID is not null
-> in this case the value shpuld be true. The first (equals(variables('V_D_MAX_LOAD_ID_HIS'), '') will be true and so we will be in the true part of the if and the output should be true.
V_D_MAX_LOAD_ID_HIS and V_D_MAX_LOAD_ID have the same value
-> in this case the first equals will be false and we will jump into the false part where the second equals is. The second equals will be true, because both have the same value. So the Output should be true.
V_D_MAX_LOAD_ID_HIS and V_D_MAX_LOAD_ID have the same value
-> The first equals will be false again, so we jump into the second equals. This one will be false to, so the output should be false
But for some reason it doesn't work. In the 3rd case the output for some reason is still true and the activity for true of the 'If-Conidition-activity' gets executed.
Where is my mistake?
Just post an answer to end this question: This is because the variable wasn't properly set.
When I added the V_D_MAX_LOAD_ID_HIS i jsut copied the set variable
activity from the V_D_MAX_LOAD_ID which already existed. Then I never
changed the variable it should be assinged to. So both Activity set
the variable for V_D_MAX_LOAD_ID and V_D_MAX_LOAD_ID_HIS was never
properly set.
Related
A scenario where the variable tempMID of type string containing value "338715618884", checks if it contains "" or not. It is returning true. Why is this happening? in my understanding, this shouldn't return true.
That's documented:
String.Contains returns true if the value parameter occurs within
this string, or if value is the empty string (""); otherwise, false.
So it's working as expected. The language designer have decided that an empty string is contained in every existing string, which makes sense to me.
I have a pipeline parameter fed by a config file in SQL.
Sometimes that parameter will be empty, not NULL but just empty ('').
How do I write an expression that will evaluate the parameter to TRUE/FALSE(blank/not blank) that I can put into my IF activity?
Basic question but thanks a lot.
I tried
#pipeline().parameters.x = ''
but it just told me Parameter x = '' was not found .......
You can use the below expression in the if activity to evaluate a parameter is empty or not.
#empty(pipeline().parameters.ok)
Sample demonstration:
A sample parameter ok.
For example, purpose I have created a string variable which I will use inside if to check the output.
In if give the above expression.
Inside True activities I have given a set variable activity and gave some value and did the same inside false activities.
Output when the parameter value is not given(empty).
Output when we gave any value to the parameter
Greetings python experts. I had written an if condition as follows that fails to be false for objects that should be false. I am writing in python 3.8.5. Note instance_list in this example contains a list of resources that are in various states. I only want to append vm_instance_list with resources that are not in a TERMINATED or TERMINATING state.
instance_results = compute_client.list_instances(
compartment_id = compartment_id).data
vm_instance_list = []
for instance in instance_results:
if instance.lifecycle_state != "TERMINATED" or instance.lifecycle_state != "TERMINATING:
vm_instance_list.append(instance)
The above code appends vm_instance_list with every object in the list instance_results, aka each condition is interpreted as True for objects that are in a TERMINATED or TERMINATING lifecycle state. I have had to re-write to nest the if conditions, which works.
for instance in instance_results:
if instance.lifecycle_state != "TERMINATED:
if instance.lifecycle_state != "TERMINATING":
vm_instance_list.append(instance)
I have no idea what why I have had to nest the above if statements and would appreciate if anyone could share some insights.
Thanks so much,
Hank
In your first version, the result is ALWAYS true, so every item is appended.
Your second version is only true if both tests are true.
If you want the first version to behave like the second version, you need an 'and' statement, not an 'or'.
Let's trace through your first if statement in the case when instance.lifecycle_state is equal to "TERMINATED". The condition is as follows:
instance.lifecycle_state != "TERMINATED" or instance.lifecycle_state != "TERMINATING"
We can see that the first part of this statement is false (since lifecycle_state DOES equal "TERMINATED". The second part is true because lifecycle_state indeed does NOT equal "TERMINATING". So this whole expression simplifies to:
False or True
which finally simplifies (by the rules of or) to be just: True. So now we have seen why the body of the if is executed in the first case.
If we do a similar process in your second code snippet, we will see that the first condition is False (since lifecycle_state DOES equal "TERMINATED". So in this case the second condition is not checked, and the body of the if does not execute.
In fact, the second snippet is equivalent to the following condition:
instance.lifecycle_state != "TERMINATED" and instance.lifecycle_state != "TERMINATING"
Note that this is very similar to your original snippet, however we've replaced or with and. In fact, two nested if statements like this are equivalent to a single condition where both parts are joined by and.
By DeMorgan's Laws, this condition is also equivalent to:
not (instance.lifecycle_state == "TERMINATED" or instance.lifecycle_state == "TERMINATING")
which you may find clearer to understand.
value is an array with objects that have a property called skuPartNumber (string). How do I make a condition that is true when there are any objects where the skuPartNumber is equal to "X" in the array.
For your requirement, you can use contains function to implement it easily. As your screenshot shows, but need to make some changes.
First, you need to know the expression of value. It seems the value comes from "Parse JSON" in your logic app. So the expression of value should be like body('Parse_JSON')?['value']. Then use a string() function to convert it to string, then judge if it contains "skuPartNumber":"x".
The expression is string(body('Parse_JSON')?['value']).
I think the solution above is easy enough, but if you don't want to think of it as a string to judge if it contains "skuPartNumber":"x". You can also loop the value array, get each item and judge if the field skuPartNumber equals to x. Do it like below screenshot:
After the "For each" loop, use a "If" condition to judge if the variable result equals true or false.
I have a problem in report studio. please help me to figure this out..
i have a optional prompt, i want to check whether the value is selected or not..
Please help how to check..
if (?parameter? is null ) then ('1') else ('2')
or
if (ParamDisplayValue('parameter') is null ) then ('1') else ('2')
Both the above are not working..
Suppose if i select any value in the prompt then the else part works and i get the result as 2, if i wont select anything then i'm not getting the result as 1
My guess, without doing extensive testing, is that an empty optional prompt doesn't exist at all and can't be compared to null. That said, I believe there's an easy fix.
Since you know that when you select an item '?parameter? is null' will return false, '?parameter? is not null' should return true and you can reverse the logic:
if (?parameter? is not null) then ('2') else ('1')
Try to put a conditional block. Set a block variable of type boolean with this expression:
ParamDisplayValue('myParam') is null
Then go to your conditional block again switch property "current block" to yes/no.
When yes (meaning that our block variable is true so the parameter is null) add a text item and just write "All".
When no add a text item with source type as report expression and write ParamDisplayValue('myParam')
P.S: there is also a way to count how many values the user selected (so as not to display all of them 1 by 1 but just show "62 values selected") but it needs some javascript and a hidden prompt field.
Use ParamCount
More details here:
http://joesanswers.blogspot.com.au/2008/09/checking-for-empty-parameters-in-cognos.html