Reputation: 89
I am trying to compare the below two values in choice connector and trying to catch the missing values from values from value 2 and value 1
Value1:
[
{
"FName": "salesforce.com"
},
{
"FName": "jobs"
},
{
"FName": "2020"
},
{
"FName": "06-2020"
}
]
Value2:
[
{
"name": "salesforce.com"
},
{
"name": "jobs"
}
]
Am using choice condition vars.NameVar == vars.SplitName
I need to catch the values "FName": "2020" and "FName": "06-2020" which is missing in value 2
Upvotes: 0
Views: 1594
Reputation: 447
Try this script. This will only show the item that doesn't match from value1 to value2
Input:
%dw 2.0
var value1=[
{
"FName": "salesforce.com"
},
{
"FName": "jobs"
},
{
"FName": "2020"
},
{
"FName": "06-2020"
}
]
var value2=[
{
"name": "salesforce.com"
},
{
"name": "jobs"
}
]
output application/json
---
value1[?(!(value2.name contains $.FName))]
Output:
[
{
"FName": "2020"
},
{
"FName": "06-2020"
}
]
The trick is to use the contains and the ! symbol. If you remove the ! it will reverse the logic, it will only display the matching values.
Upvotes: 0
Reputation: 25812
Script:
%dw 2.0
output application/json
import * from dw::core::Arrays
var a=[
{
"FName": "salesforce.com"
},
{
"FName": "jobs"
},
{
"FName": "2020"
},
{
"FName": "06-2020"
}
]
var b=[
{
"name": "salesforce.com"
},
{
"name": "jobs"
}
]
---
leftJoin(a, b, (x) -> x.FName, (x) -> x.name)
filter !$.r?
map $.l
Output:
[
{
"FName": "2020"
},
{
"FName": "06-2020"
}
]
Upvotes: 1