Using Import Filter on step after Lookup
I built a flow with a lookup to get Shopify Transaction data, and renamed the fields with lookup transformation and returned Results Mapping of data : SFY_data.
Defining a branch condition, I can see the SFY_data in my input preview, but the fields are not available from the rule selector (operand = Field, String).
{
"record": {
"id": "1014611",
...
"SFY_data": [
{
"SFY_gateway": "stripe",
"SFY_created_at": "2023-01-01T01:48:36-05:00",
"SFY_authorization": "ch_12345abcde",
"SFY_source_name": "999999",
"SFY_amount": "37.53",
"SFY_status": "success"
}
I tried a simple input filter instead, thinking maybe branching was the issue, but Under Define input Filter I have the same result.
I reviewed the documentation on Branching and Filtering, and Lookups, and I can't seem to find the issue I'm experiencing. I tried a javascript rule based on the example in the branch script article, but that's bypassing both if () conditions and returning the final else despite meeting criteria for branch [1].
function branching (options) {
if (options.record.SFY_data.SFY_source_name === "Subscription Contract")
return [0]
else if(options.record.SFY_data.SFY_source_name === "999999")
return [1]
else
return [2]
}
Am I missing something about how lookups and filters interact?
Thanks
-
Hi Rob Riccio, it's not currently possible to filter on fields within flow branching within an array without using some javascript, so you were on the right path. On your lookup step, where you are getting the transaction data, will you potentially have multiple transactions for a single record lookup? I assume if you are looking up based on order number, then you could have multiple transactions tied to it and therefore have multiple records returned for a single order. If that's the case, then the array in result mapping is the right choice here and you can skip to the next paragraph. If, however, you will only ever get 1 result from the lookup (only 1 transaction for whatever you are looking up), then you could change your result mapping to be data.0.field1, data.0.field2, etc.. By doing that, you wouldn't have the array and then could use the UI branch filtering.
If you will have multiple transactions returned from the lookup for a single record, then could each transaction within the array have a different source? For example, could the first object in the array have a source of "subscription contract" and the second object have a source of "sample sample"? If so, would you need to process each object within the array on it's own or just the first object is the master?
As for why your javascript isn't working, you need to specify your array position within your if statement. Here is a screenshot and update code block. Hope this helps!
function branching (options) {
if (options.record.SFY_data[0].SFY_source_name === "Subscription Contract")
return [0]
else if(options.record.SFY_data[0].SFY_source_name === "999999")
return [1]
else
return [2]
}1 -
Hi Tyler,
Thank you; I came to the same conclusion myself this morning by process of elimination, and your answer certainly would have helped if I hadn't! Just checking - when you said:
If so, would you need to process each object within the array on it's own or just the first object is the master?
I think if each on its own:
if (options.record.SFY_data[*].SFY_source_name
and if the first is the master, like you showed in your example:
if (options.record.SFY_data[0].SFY_source_name
is that right?
0 -
Rob Riccio what is the overall goal of this flow so I can maybe better help with suggestions?
For flow branching, it's processing the singular record, not the child objects within your SFY_data array. You could loop through each object within the transaction array, but you ultimately still need a single outcome. For example, if you had 10 transactions within that array, and each had a different source, you would need to figure out what branch to send the main record. Does that make sense?
If I knew what exactly you were trying to accomplish I could suggest a few things:
- You may not need flow branching and instead maybe just need an import step, set to one-to-many, then map the source to your destination.
- You may need another flow to string with this one where you send each individual transactions, then have branching logic there.
0 -
Hi Tyler Lamparter -
I have a very similar related follow up; I'm now trying to branch for criteria = Shopify app_id from Shopify order data from a single order lookup based on {{shopify_order_id}}. The app_id's have different data mapping to pull Walmart number either from Notes field or Notes Attribute array on my import (which I have a hook for). I'm merging Shopify Order data from the lookup with NetSuite data from the original export.
{
"record": {
"id": "1278981",
"recordType": "customerdeposit",
"Internal ID": "1278981",
"Shopify Order ID": "4939768823889",
...
"SFY_data": [
{
"SFY_note_attributes": [
{
"name": "walmart Number",
"value": "108801356244587"
},
{
"name": "Fulfillment done on walmart",
"value": "true"
}
],
"SFY_gateway": "walmart via Shopping Feed",
"SFY_created_at": "2023-01-12T00:00:53-05:00",
"SFY_app_id": 167285,
"SFY_total_price": "30.57",
"SFY_fulfillment_status": "fulfilled"
}
]
},I tried options.record.SFY_data.SFY_app_id, options.record.SFY_data[0].SFY_app_id, and [*]; both of the first two syntax pass through to branch [2] despite meeting branch [0], and the [*] throws an error.
function branching (options) {
if (options.record.SFY_data.SFY_app_id === "167285")
{return [0]}
else if(options.record.SFY_data.SFY_app_id === "3542705")
{return [1]}
else
{return [2]}
}For additional context to your last question; my original flow did as intended once I updated to the syntax to the below. All transactions returned by the lookup for a given order would have the same 'source_name', as it represented basically whether the order was coming through our new subscription platform or legacy platform, which had somewhat different data config and thus the charge ID I needed was in a different output field to map from depending.
options.record.SFY_data[0].SFY_source_name
0 -
UPDATE:
the quotes seem to have been causing the issue on the criteria value, not being returned as a string in the input data:
if (options.record.SFY_data[0].SFY_app_id === "167285"
should be:
if (options.record.SFY_data[0].SFY_app_id === 167285
0 -
Rob Riccio since that branching logic is JavaScript, using 3 equal signs vs 2 equal signs makes a difference. When using 3, the value and data type need to be the same. If using 2, then the value needs to be the same, but data type can be different. There are nuances to that, but in general that's why you had an issue and why removing the quotes made it work. See supporting JavaScript reasoning: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness.
1
Please sign in to leave a comment.
Comments
6 comments