Azure Logic App condition - Property contains in object within an array - azure

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.

Related

Why a string that has some value is returning true when checking if it contains ""?

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.

How to write an expression that evaluates a pipeline parameter to TRUE/FALSE?

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

Groovy ArrayList contains method

I'm facing an issue with my groovy script which I cannot figure out why it is happening.
Basically I'm trying to check if my ArrayList:
list = [image-ab, image-cd]
contains the following string
string = 'cd'
If I use the 1st condition, it returns "true":
if (list[1].contains(string))
If I use the 2nd condition, it returns "false":
if (list.contains(string))
Why is this happening and how must I adapt 2nd condition to work?
In the first case, you access the second element of the list list[1], and you call String.contains(str) method on the returned string. It returns true because indeed image-cd contains cd. If you do the same with list[0], you would get false because the string image-ab does not contain cd.
In the second case, you call contains() method on a list, not an element of the list. This method returns true if the list contains the exact cd string. And you see false because there is no cd element in the list.
What you may want to do is to use list.any() method that allows you to check if any element of the list matches given predicate. For instance,
list.any { el -> el.contains("cd") }
will return true if at least one element from that list contains cd.
The alternative for any method is every, which expects that every element of the list matches given predicate. For instance,
list.every { el -> el.contains("cd") }
would return false in your case, because image-ab does not contain cd in the string.

Ampscript BuildRowsetFromString() fails on single item

I've been tasked with an ExactTarget task, which uses Ampscript. Trying to learn on the go here. See code snippet below:
%%[
Var #testString, #testOutput
Set #testString = Qwerty
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
TestOutput:%%= v(#testOutput) =%%
The code works if the testString contains a ~, but when there is no ~ character in the string, the ouput is blank. Is this correct by design? Do I need to add a conditional to check for the presence of the ~ character?
That's the expected behavior. The BuildRowsetFromString() function alone isn't going to return any value when displayed, you're going to need to use Row() and Field() in order to pull the value out.
Using your example:
%%[
Var #testString, #testOutput
Set #testString = "Qwerty"
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
RowCount: %%=RowCount(#testOutput)=%%
TestOutput: %%=v(#testOutput)=%%
The RowCount() function returns a value of 1, essentially saying it knows there's at least one 'row' in there. To display that one value, you'll need to wrap that value with Field() and Row():
TestOutput: %%=Field(Row(#testOutput,1),1)=%%
If you want to display other values in the string, say you were passing "Qwerty~Second~Third", you'll need to either change the number at the Row() function or perform a loop.
References
Using Loops
BuildRowsetFromString() Function

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Resources