cancel
Showing results for 
Search instead for 
Did you mean: 

Filter output from Sharepoint Online - Search Items Snap

Pud24
New Contributor

I’m in the process of designing a pipeline which will read all of the .pgp files from a sharepoint document library and then delete any over X amount of days.

To do this I am first using a Sharepoint Online - Search Items snap to search for all .pgp documents in the specified library.

However I can’t for the life of me get the filter working so that it leaves me with only files older than X days.

My Sharepoint snap returns the following and I want to filter on createdDateTime
image

So far I have attempted a filter snap using the following but that filters everything out.

Date.parse(jsonPath($, “$value[*].createdDateTime”)) < Date.now().minusDays(2)

I have noticed that if i amend this filter snap to the following it does work as i pass each individual array member (using the array position rather than the * above) but i need it to filter based on the entire array.

Date.parse(jsonPath($, “$value[1].createdDateTime”)) < Date.now().minusDays(2)

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @Pud24 ,

This is happening because you have array of objects and when you try to filter on createdDateTime, the filter snap will evaluate either to true or false but if a condition is true it will pass the whole array and if the condition is false nothing will pass.

You have to do the following:

  1. Use a JSON Splitter snap to split the data in the array into separate objects and then use the Filter snap and then use a Group by N snap to put all the documents into a single array agian.
  2. You can use a Mapper and the .filter() method, this will filter all values that do not match the criteria in the array but will leave the input as an array.

Use the following expression: $value.filter(val => Date.parse(val.get("createdDateTime")) < Date.now().minusDays(2))

View solution in original post

2 REPLIES 2

j_angelevski
Contributor III

Hi @Pud24 ,

This is happening because you have array of objects and when you try to filter on createdDateTime, the filter snap will evaluate either to true or false but if a condition is true it will pass the whole array and if the condition is false nothing will pass.

You have to do the following:

  1. Use a JSON Splitter snap to split the data in the array into separate objects and then use the Filter snap and then use a Group by N snap to put all the documents into a single array agian.
  2. You can use a Mapper and the .filter() method, this will filter all values that do not match the criteria in the array but will leave the input as an array.

Use the following expression: $value.filter(val => Date.parse(val.get("createdDateTime")) < Date.now().minusDays(2))

This worked perfectly - thank you!