Filter expression evaluate against all input documents

Hi All,

I am currently working on an integration which requires a subset of the documents I currently have.

e.g.

ID | Name| Position | SecID
1 |Bob | Architect |4
2 |Joe | Architect |3
3 |Steve | Secretery |
4 |Martin| Assistant |
5 |Eric | BA |
6 |Tom | PM | 5

This subset in this example would be the the list of all records with the position architect and also there secretaries

E.g.

ID | Name| Position | SecID
1 |Bob | Architect |4
2 |Joe | Architect |3
3 |Steve | Secretery |
4 |Martin| Assistant |

I am aware I can do this in a script snap but wondering how if at all this could be done in the filter snap in a single expression?

With the data you gave in the example, if you use this expression:
["Secretery", "Architect"].indexOf($Position) != -1

in the Filter snap, it will only return documents which have “Secretery” or “Architect” as the value at $Position

There are a number of expressions you could use to do this, if you want to use one that is safe to use if the field ‘Position’ is optional you can use this expression as well:
$.get("Position") == "Architect" || $.get("Position") == "Secretery"

Or just simply replace the $Position in the first expression with $.get("Position") to make the first expression null safe as well. Just wanted to give some options for what makes sense to you in your case.

Thanks @cjhoward18

I did initially look at this kind of solution however not all secretary are given a position of secretary some may be assistant or receptionist. the other problem is that not all secretaries report to architects.

If i was to write a script i would iterate through the document filtering firstly on architects and add them to a seperate list then if they have a secretery ID I would append those secretaries to that list.

Im wondering if this can be done without the script snap though as I would prefer to use the out the box components to make the support aspect of this easier however it may be a case that script is the simplest way to go

So, if I understand this correctly, you just want all the documents where $Position == “Architect” OR the ID is a SecID for one of the Architects. That is a bit complex to do in a single filter snap expression. But, still easy to do with the native components. Here is an attached pipeline, that uses a CSV Generator to create your example data, then a group By snap to group the documents. From there we can use a Mapper to collect all the secretary ID’s of the Architects in a list to use later. In the final Mapper we can filter the list of documents based on if they are an Architect or if their ID is an ID in the SecID list we created previously from the list of Architect Secretary ID’s.

Here is the pipeline please let me know any questions of problems you run into.

extractArchitectsAndAssistants.slp (6.0 KB)

1 Like

Hi Ksalem,

Good day, in the scenario where you want to consolidate or group by Position I usually do is a combination of array and object methods… here it goes…

First I tagged all the documents to have a groupId (pipe.ruuid) then group by fields groupId
Then create the objects (Positions) that will hold the array of information then filter main array and keep the item where Position is equal to the key
Then did some cleanup removing the groupId then lastly filtering the array of each position if SecID is empty remove it (I think here you can place your custom rules of filtering)