How can i run a propery in logic app for each only first run of the loop? - expression

Is it possible to remove a property after the first run in the foreach loop, i want to remove the property "pickedQuantity".

To remove properties from an object you can use
removeProperty function
https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#removeProperty
But not sure how this is possible in your loop. If you always want to remove it after the first run, why not do the first "run" outside the loop, then loop the rest?

One of the workaround is to add the property outside the foreach loop in order to have it only once. For instance here is the sample json I have taken
{
"shipmentLines":
[
{
"PART_NO":1,
"WEB_ORDER_LINE_NUMBER":20,
"WEB_ORDER_NUMBER":30
},
{
"PART_NO":2,
"WEB_ORDER_LINE_NUMBER":298,
"WEB_ORDER_NUMBER":347
}
]
}
This is my Logic app where I'm storing the Compose content to an array variable and removing the pickedQuantity property and added after the foreach loop:-
Here is the Json code in my Compose 2 Connector.
{
"shipmentLines": [
{
"pickedQuantity": "1",
"shipmentDetails": #{variables('SampleArray')}
}
]
}
Here is the output:-
The Final Compose output:-
{
"shipmentLines": [
{
"pickedQuantity": "1",
"shipmentDetails": [
{
"shipmentLines": [
{
"articleNo": "2",
"customerOderNo": "347",
"lineNumber": "298"
}
]
},
{
"shipmentLines": [
{
"articleNo": "1",
"customerOderNo": "30",
"lineNumber": "20"
}
]
}
]
}
]
}

Related

Generate multiple output tokens from a single input token in Amazon Style Dictionary

I am using Amazon Style Dictionary to generate SCSS variables from JS definition files. Given the following input:
module.exports = {
color: {
border: {
focus: { value: '#0071ff' }
}
}
}
I would like to generate not one output variable for this, but two (HEX and RGB). Is it possible to write a custom value transformer that spits out multiple values for a given input? Or do I need to run a separate pipeline for this use case?
This could be your colors.json file configuration
"source": ["sources/colors.js"],
"platforms": {
"css-rgb": {
"transforms": ["color/rgb"],
"buildPath": "dist/rgb/",
"files": [
{
"destination": "colors-rgb.css",
"format": "css/variables"
}
]
},
"css-hex": {
"transforms": ["color/hex"],
"buildPath": "dist/hex/",
"files": [
{
"destination": "colors-hex.css",
"format": "css/variables"
}
]
}
}
to provide to your StyleDictionary configuration.
So you grab the sources from your sources/colors.js file and create in output in the dist folder two subfolders, rgb containing colors-rgb.css and hex containing colors-hex.css.

How can I modify array fields in place?

Let's say I have this object:
{
"id": "1a48c847-4fee-4968-8cfd-5f8369c01f64" ,
"sections": [
{
"id": 0 ,
"title": "s1"
} ,
{
"id": 1 ,
"title": "s2"
} ,
{
"id": 2 ,
"title": "s3"
}
]
}
How can I directly change 2nd title "s2" to other value? without loading the object and save again? Thanks.
Update plus the changeAt term:
r.table('blog').get("1a48c847-4fee-4968-8cfd-5f8369c01f64").update(function(row){
return {
sections: row('sections').changeAt(1,
row('sections')(1).merge({title: "s2-modified"}))
}
}
The above is good if you already know the index of the item you want to change. If you need to find the index, then update it, you can use the .offsetsOf command to look up the index of the element you want:
r.table('table').get("1a48c847-4fee-4968-8cfd-5f8369c01f64").update(function(row){
return row('sections').offsetsOf(function(x){
return x('title').eq('s2')
})(0).do(function(index){
return {
sections: row('sections').changeAt(index,
row('sections')(index).merge({title: "s2-modified"}))
}
})
})
Edit: modified answer to use changeAt

How to use two conditon in one array?

I have a list of task stored in Mongo, like below
{
"name": "task1",
"requiredOS": [
{
"name": "linux",
"version": [
"6.0"
]
},
{
"name": "windows",
"version": [
"2008",
"2008R2"
]
}
],
"requiredSW": [
{
"name": "MySQL",
"version": [
"1.0"
]
}
]
}
My purpose is to filter the task by OS and Software, for example the user give me below filter condition
{
"keyword": [
{
"OS": [
{
"name": "linux",
"version": [
"6.0"
]
},
{
"name": "windows",
"version": [
"2008"
]
}
]
},
{
"SW": [ ]
}
]
}
I need filter out all the task can both running on the windows2008 and Linux 6.0 by searching the "requiredOS" and "requiredSW" filed. As you seen, the search condition is an array (the "OS" part). I have a trouble when use an array as search condition. I expect the query to return me a list of Task which satisfy the condition.
A challenging thing is that I need to integrate the query in to spring-data using #Query. so the query must be parameterized
can anyone give me a hand ?
I have tried a query but return nothing. my purpose is to use $all to combine two condition together then use $elemMatch to search the "requiredOS" field
{"requiredOS":{"$elemMatch":{"$all":[{"name":"linux","version":"5.0"},{"name":"windows","version":"2008"}]}}}
If I understood correctly what you are trying, you need to use $elemMatch operator:
http://docs.mongodb.org/manual/reference/operator/query/elemMatch/#op._S_elemMatch
Taking your example, the query should be like:
#Query("{'requiredOS':{$elemMatch:{name:'linux', version:'7.0'},$elemMatch:{name:'windows', version:'2008'}}}")
It match the document you provided.
You basically seem to need to translate your "parameters" into a query form that produces results, rather than passing them straight though. Here is an example "translation" where the "empty" array is considered to match "anything".
Also the other conditions do not "literally" go straight through. The reason for this is that in that form MongoDB considers it to mean an "exact match". So what you want is a combination of the $elemMatch operator for multiple array conditions, and the $and operator which combines the conditions on the same property element.
This is a bit longer than $all but essentially because that operator is a "shortened" form of $and as $in is to $or:
db.collection.find({
"$and": [
{
"requiredOS": {
"$elemMatch": {
"name": "linux",
"version": "6.0"
}
}
},
{
"requiredOS": {
"$elemMatch": {
"name": "windows",
"version": "2008"
}
}
}
]
})
So it just a matter of transforming the properties in the request to actually match the required query form.
Building this into a query object can be done in a number of ways, such as using the Query builder:
DBObject query = new Query(
new Criteria().andOperator(
Criteria.where("requiredOS").elemMatch(
Criteria.where("name").is("linux").and("version").is("6.0")
),
Criteria.where("requiredOS").elemMatch(
Criteria.where("name").is("windows").and("version").is("2008")
)
)
).getQueryObject();
Which you can then pass in to a mongoOperations method as a query object or any other method that accepts the query object.

How to select from array in Rethinkdb?

I have a field bidder with arrays and objects like this(it can be also empty):
[
[
{
"date":"08/17/1999"
},
{
"time":"07:15:23"
},
{
"increase":31.5
}
],
[
{
"date":"04/01/1998"
},
{
"time":"01:06:18"
},
{
"increase":10.5
}
]
]
How can I select first-array's increase value that means output should be 31.5.
In JavaScript
r.table('test')('bidder').nth(0)('increase').run(conn, callback)
In Python and Ruby
r.table('test')['bidder'][0]['increase'].run(conn)
Edit: Queries for all documents
If you need to do more complex things that just returning a value, you can use the general "form" with map
r.table('test').map(function(doc) {
return doc('bidder').nth(0)('increase')
}).run(conn, callback)

Validate a $Location in Firebase

I am trying to do some validation on incoming data into my firebase app. My structure is at the bottom. I have removed existing validation rules for clarity - however we can assume that reads and writes are allowed at the root rules level.
$categoryid will look something like this:
1234: {1:{...}, 2:{...}, 3:{...}}
I want to ensure that $categoryid (which is 1234 in the above example) is numerical - however the rule ".validate": "$categoryid.isNumeric()" results in an "no such method or property" error.
I could check for data.child($categoryid) in categories, however the variable doesn't exist at that level and results in an "unknown variable" error.
I'm sure I'm missing a trick here...
{
"rules": {
"categories": {
"$categoryid": {
"$itemid": {
"members": {
"$id": {
}
}
}
}
}
}
}
There is currently no good way to do this, but there is a hacky work around that involves storing the $categoryId in a field, then checking that that field is numeric.
Using these security rules:
{
"rules": {
"categories": {
"$categoryid": {
".validate": "'' + newData.child('meta/id') === $categoryId && newData.child('meta/id').isNumber()"
"meta": {},
"items": {
"$itemid": {
"members": {
"$id": {
}
}
}
}
}
}
}
}
We can then create a new category by running:
categoriesRef.child(1234).set({meta: {id: 1234}});
These rules will check that a) the $categoryId matches $categoryId/meta/id and that $categoryId/meta/id is a number.
To do this validation you can use RegEx /^[0-9]+$/
{
"rules": {
"categories": {
"$categoryid": {
.validate": "$categoryid.matches(/^[0-9]+$/)"
"$itemid": {
"members": {
"$id": {
}
}
}
}
}
}
}

Resources