$filter array is return undefined in logs - flow.fileContents or payload.arrayEntry not accessible?

I am trying $filter a subset of json based an email address in the JSON payload which I copied to flow.fileContents context data (attached), trying many variations of the function syntax. I get a $distinct list of emailAddress copied to msg.arrayEntry, and then I use the Rollun Common foreach successfully iterate on that list.

This JSONata is return undefined. I also tried flow.fileContents without the $. msg.arrayEntry and $msg.arrayEntry were previously attempted (legacy message disappeared when I switched to payload.arrayEntry).

Why am I missing? Is flow not accessible inside JSONata?

$filter(
  $flow.fileContents,
   function($v) {
       $v.farmerEmailAddress = payload.arrayEntry 
   }
)

tstCSV.json (1.9 KB)

It is but in a different manner

Thank you that was helpful in checking the flow reference while debugging (yes, the data is still in the flow context), but I still get undefined in the $filter statement:

$filter(
  $flowContext("fileContents"),
   function($v) {
       $v.farmerEmailAddress = payload.arrayEntry 
   }
)

Do you have more than one context store?
What is the value of payload.arrayEntry ?
Is the flow context saved in same flow tab?

  1. One context store
  2. Context is in the same flow tab, of course (thanks for asking). Data is there as per debug:

Debug config:

  1. payload.arrayEntry:
    On the first iteration of the for-each
node: emailAddress in the loop
c:\\temp\\reportingTail : msg.arrayEntry : string[23]
"steve.cropper@gmail.com"

On the second iteration of the for-each

node: emailAddress in the loop
c:\\temp\\reportingTail : msg.arrayEntry : string[15]
"paddy@gmail.com"

This should be a similar filter to this JSON PATH which IMHO is what JSONata should leverage (just saying):

$[?(@.farmerEmailAddress=="paddy@gmail.com")]

You can see in my screen shot I also tried the jsonpath node that is out there, but it is not ready for prime-time.

msg.arrayEntry, but the jsonata references msg.payload.arrayEntry.

But I sse we are at cross purposes, as i am asking about the payload going into the change node, not the iterations of the $filter

$v is the payload? Or is it the full $flowContext("fileContents") set prior to the function()?
The documentation does not explicitly clarify that.

$v is the the object iterations of the flow context

@E1cid thank you! That was it.
I reassigned my emailAddressList to msg.emailAddressList and the for-each on output to emailAddress instead of payload.

The $filter function is now:

  $flowContext("fileContents"),
   function($v) {
       $v.farmerEmailAddress = msg.emailAddress 
   }
)

And the results are perfect!

its as if $flowContext("fileContents") has no 'value' in the $filter. Its all about payload (again) -- so much store and restoring back to payload.

To note, if theere is only one match the output will be an object not an array with a single object, this maybe OK for you, but if you require an array of object/s then enclose the expression in square brackets to force an array output.

 [$flowContext("fileContents"),
   function($v) {
       $v.farmerEmailAddress = msg.emailAddress 
   }
)]

Thanks, that is a good preventative measure.

I will test for that now.

That didn't quite work:


$filter(
   [
       $flowContext("fileContents"),
       function($v) {
           $v.farmerEmailAddress = msg.emailAddress 
   }
   ]
)


I will play around more.

Creating more test data.

Tested this.

[
   $filter(
       $flowContext("fileContents"),
       function($v) {
           $v.farmerEmailAddress = msg.emailAddress 
   }
   
)
]

Worked

versus without wrapper:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.