Trying to Add more than 2 variables in Logic App Cosmos DB - add

Requirement in Logic App : Need to add 4 variables into a single variable.
I am using the expression Add(Variable1, variable2, variable3, variable4)
But it throws the below error.
Is there any other way to add 4 variables(int).

Compound them, i.e. use this concept ...
add(add(add(variables('Number 1'), variables('Number 2')), variables('Number 3')), variables('Number 4'))
This test flow ...
... gives me this result when I add them using that compound approach ...
However, if the amount of numbers you're adding is dynamic, you may need to loop.

Since Add()'s synatx is Add(summand1,summand2), you can do something like below
Add(variables('Variable1'),Add(variables('Variable2'),Add(variables('Variable3'),variables('Variable4'))))
Here is my logic app
RESULT:

Related

How to stuff a result of a query into a variable and use it another query in a logic app

I haven't used logic apps a lot, my boss is having trouble stuffing the results of one query into a variable and then using that variable in another query.
Basically, all he wants to do is get a list of of Id's returned from the first query and use that list in the second.
Here is a picture of what his logic app looks like:
You can see at the end of the second query he wants to check if the id is in the list or not. He's out for the day and I'm not sure if that variable is even receiving the list of id's successfully, but is there anything from the picture that you can tell that needs to be corrected? Or any suggestions that he could try, to achieve what he's trying to achieve?
According to the image, no data is getting stored into the variable AppId. While in the query you can just directly use c.EntityId. Below query to check if c.id is present in c.EntityId.
SELECT c.Vechicle.GrossVechicleWeight as GVW, c.EntityId as ApplicationId FROM c where c.RiskTypeId = 1 and c.Discriminator = 'RiskEntity' and c.EntityTypeId = 4500 and c.id in (c.EntityId)
Consider if you are trying to store c.Entity into AppId variable then you can Query SELECT c.EntityId FROM c and then store the result into the variable using Append to array variable action by extracting only c.EntityId using Parse JSON.
Here is my logic app
RESULT:

Update a parameter value in Brightway

It seems to be a simple question but I have a hard time to find an answer to it. I already have a project with several parameters (project and database parameters). I would like to obtain the LCA results for several scenarios with my parameters having different values each time. I was thinking of the following simple procedure:
change the parameters' value,
update the exchanges in my project,
calculate the LCA results.
I know that the answer should be in the documentation somewhere, but I have a hard time to understand how I should apply it to my ProjectParameters, DatabaseParameters and ActivityParameters.
Thanks in advance!
EDIT: Thanks to #Nabla, I was able to come up with this:
For ProjectParameter
for pjparam in ProjectParameter.select():
if pjparam.name=='my_param_name':
break
pjparam.amount = 3
pjparam.save()
bw.parameters.recalculate()
For DatabaseParameter
for dbparam in DatabaseParameter.select():
if dbparam.name=='my_param_name':
break
dbparam.amount = 3
dbparam.save()
bw.parameters.recalculate()
For ActivityParameter
for param in ActivityParameter.select():
if param.name=='my_param_name':
break
param.amount = 3
param.save()
param.recalculate_exchanges(param.group)
You could import DatabaseParameter and ActivityParameter iterate until you find the parameter you want to change, update the value, save it and recalculate the exchanges. I think you need to do it in tiers. First you update the project parameters (if any) then the database parameters that may depend on project parameters and then the activity parameters that depend on them.
A simplified case without project parameters:
from bw2data.parameters import ActivityParameter,DatabaseParameter
# find the database parameter to be updated
for dbparam in DatabaseParameter.select():
if (dbparam.database == uncertain_db.name) and (dbparam.name=='foo'):
break
dbparam.amount = 3
dbparam.save()
#there is also this method if foruma depend on something else
#dbparam.recalculate(uncertain_db.name)
# here updating the exchanges of a particular activity (act)
for param in ActivityParameter.select():
if param.group == ":".join(act.key):
param.recalculate_exchanges(param.group)
you may want to update all the activities in the project instead of a single one like in the example. you just need to change the condition when looping through the activity parameters.

Is there a way to pass a parameter to google bigquery to be used in their "IN" function

I'm currently writing an app that accesses google bigquery via their "#google-cloud/bigquery": "^2.0.6" library. In one of my queries I have a where clause where i need to pass a list of ids. If I use UNNEST like in their example and pass an array of strings, it works fine.
https://cloud.google.com/bigquery/docs/parameterized-queries
However, I have found that UNNEST can be really slow and just want to use IN on its own and pass in a string list of ids. No matter what format of string list I send, the query returns null results. I think this is because of the way they convert parameters in order to avoid sql injection. I have to use a parameter because I, myself want to avoid SQL injection attacks on my app. If i pass just one id it works fine, but if i pass a list it blows up so I figure it has something to do with formatting, but I know my format is correct in terms of what IN would normally expect i.e. IN ('', '')
Has anyone been able to just pass a param to IN and have it work? i.e. IN (#idParam)?
We declare params like this at the beginning of the script:
DECLARE var_country_ids ARRAY<INT64> DEFAULT [1,2,3];
and use like this:
WHERE if(var_country_ids is not null,p.country_id IN UNNEST(var_country_ids),true) AND ...
as you see we let NULL and array notation as well. We don't see issues with speed.

How to append array data to array variable in logic app?

I'm calling API using HTTP connector getting result array data. and used until loop. so every time i will get some records into result array.
Now I want to append all records so that i will those all.
Like 1st time i got 2 records like below and 2nd time 1 then I want to append so that it will be 3 total.
1st iteration result -
"results":[
{"id":"2","name":"t1"},{"id":"3","name":"t4"}
]
2nd iteration result -
"results":[
{"id":"66","name":"i7"}]
I want to append all data so that final result will be like -
[{"id":"2","name":"t1"},{"id":"3","name":"t4"}, {"id":"66","name":"i7"}]
instead of foreach I tried using append array variable but it throws below error -
its a type of array need to be string to append.
I can able to achieve it using foreach but it does not make sense just to add values use foreach instead if we found any way to directly add array it will be great.
You can use JS inline code to implement your requirement. I did some test on my side, post to arrays(result1 and result2) to logic app and compose them using JS :
Result :
Please note if you want to use this feature , you should create an integration account and associated with your logic app in "Workflow settings" blade .
The above solution works only if you have integration account.
Other simple option - use union function inside compose action to append two array collections:
union(variables('ResponseArray'),body('Response'))
https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#union

LookUpRows on rowset created with function BuildRowSetFromString

Is it possible to apply a function like LookUpRows or Lookup to an array created with BuildRowSetFromString?
I have this:
SET #rowSet = BuildRowSetFromString(#ItemsString2, '|')
I'd like to know if there's a function on which I can do:
SET #var = LookupRows(#rowSet, ITEM_ID, ... )
I am trying already using a FOR loop. I want to know if there's a function that can do this.
No. I wish.
Best bet would be to use arrays in Server-Side JavaScript or possibly GTL.
If you want to over-engineer it, you can use XML and XPATH to do some array functions in AMPScript. I've written up a use-case with examples here on my personal blog.
Also, there is a lot more SFMC dicussion going on over in http://salesforce.stackexchange.com.

Resources