Watcher code help - filter out values in the file.path

I am looking for some help in modifying this watcher to remove Revit files that contain “Training” or “UNO3” (in the file.path). We are currently using this watcher to create a list for our process automation to run snapshots over the weekend. I need to remove some of the projects that we do not want to run a snapshop on.

Would anyone be able to help me with this?

Here is my existing watcher.
{
“trigger”: {
“schedule”: {
“interval”: “6d”
}
},
“input”: {
“search”: {
“request”: {
“search_type”: “query_then_fetch”,
“indices”: [
revit-event
],
“rest_total_hits_as_int”: true,
“body”: {
“_source”: {
“includes”: [
@timestamp”,
“_id”,
“software.version”,
“computer.name”,
“file.path”,
“bim360.project”,
“bim360.model”
]
},
“aggs”: {
“0”: {
“terms”: {
“field”: “file.path”,
“order”: {
“_key”: “desc”
}
}
}
},
“size”: 1000,
“query”: {
“bool”: {
“must”: [
{
“query_string”: {
“query”: “”“software.version: Autodesk\ Revit\ 2025*”“”,
“analyze_wildcard”: true
}
}
],
“filter”: [
{
“match_phrase”: {
“action.name”: “Open”
}
},
{
“exists”: {
“field”: “software.version”
}
},
{
“exists”: {
“field”: “computer.name”
}
},
{
“exists”: {
“field”: “bim360.project”
}
},
{
“range”: {
@timestamp”: {
“format”: “strict_date_optional_time”,
“gte”: “now-6d/d”,
“lte”: “now/d”
}
}
}
],
“should”: [],
“must_not”: [
{
“match_phrase”: {
“computer.name”: “xxxxxxxxxxxxxxxxxx”
}
}
]
}
}
}
}
}
},
“condition”: {
“compare”: {
“ctx.payload.hits.total”: {
“gte”: 1
}
}
},
“actions”: {}

Hello Gilly,

It looks like this watcher returns a list of file.path values for Revit 2025 files that were open in the last 6 days.

This portion is already filtering out documents where computer.name is xxxxxxxxxxxxxxxxxx

“must_not”: [
{
“match_phrase”: {
“computer.name”: “xxxxxxxxxxxxxxxxxx”
}
}
]

We can add your desired file.path exclusions to this exception.

"must_not": [
  {
    "match_phrase": {
      "computer.name": "xxxxxxxxxxxxxxxxxx"
    }
  },
  {
    "wildcard": {
      "file.path": "*Training*"
    }
  },
{
    "wildcard": {
      "file.path": "*UNO3*"
    }
  }
]

I hope this helps!

This worked great. One follow up question. With the changes to webhooks and teams how does that impact the webhook posting to teams? Do I need to add an adaptive card to the teams webhook for it to work?

This is what we had done before -
“condition”: {
“compare”: {
“ctx.payload.hits.total”: {
“gte”: 1
}
}
},
“actions”: {
“post-to-teams”: {
“webhook”: {
“scheme”: “https”,
“host”: “FIRMNAME.webhook.office.com”,
“port”: 443,
“method”: “post”,
“path”: “/webhookb2/9f3e6d8a-a4cd-4371-b5f7-cb278c09ae34@1ac47f5d-9b82-47e4-a0c2-39a1c1ea8835/IncomingWebhook/4a3d6b889c124a2ea61e9fc71e48d6c3/fd2a1d67-834e-43b6-9b4f-8cd8a19af3c9”,
“params”: {},
“headers”: {
“Content-Type”: “application/json”
},
“body”: “”“{“type”:“message”,“attachments”:[{“contentType”:“application/vnd.microsoft.card.adaptive”,“contentUrl”:null,“content”:{”$schema":“http://adaptivecards.io/schemas/adaptive-card.json","type”: “AdaptiveCard”,“version”: “1.4”,“id”: “Revit 2024 is running on OLD VERSION”,“body”: [{“type”: “ColumnSet”,“columns”: [{“type”: “Column”,“width”: 1,“items”: [{“type”: “Image”,“size”: “Large”,“url”: “https://archi-lab.net/wp-content/uploads/2023/05/bimbeatsLogo_square.png"}]},{"type”: “Column”,“width”: 2,“items”: [{“type”: “TextBlock”,“text”: “Revit 2024 is running on OLD VERSION”,“wrap”: true,“fontType”: “Monospace”,“size”: “Large”,“separator”: true,“horizontalAlignment”: “Left”,“weight”: “Bolder”},{“type”: “TextBlock”,“text”: “Must update the following Computer Host ASAP”,“wrap”: true,“size”: “Medium”,“fontType”: “Monospace”},{“type”: “TextBlock”,“text”: “{{ctx.payload.message}}”,“wrap”: true,“fontType”: “Monospace”}]}]},{“type”: “ActionSet”,“actions”: [{“type”: “Action.OpenUrl”,“title”: “IT - Revit Version Troubleshooting”,“url”: “https://bimbeats-6ddd50.kb.us-east-2.aws.elastic-cloud.com:9243/s/interstates-ds-production/app/dashboards#/view/25b039d0-0576-11ee-ab7e-7db6a0943ed3?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-7d%2Fd,to:now))”,“toottip”: “Navigate to Troubleshooting Dashboard”,“id”: “button_id”}]}],“msteams”: {“width”: “Full”}}}]}“”"
}
}
},
“transform”: {
“script”: {
“source”: “”"
def finalMessage = “OLD VERSIONS OF REVIT: \n\n”;
def computers = [];
for (def bucket : ctx.payload.aggregations.0.buckets) {
def version = bucket.1.hits.hits[0].fields[‘software.version’][0];
def computer = bucket.key;
finalMessage += "Computer: " + computer + “\n”;
finalMessage += “Version: " + version + “\n”;
}
return [“message”: finalMessage];
“””,
“lang”: “painless”
}
}
}

Yes, unfortunately due to the changes in the webhook you now need to use the Workflows app within Microsoft Teams to create a new webhook. We created a video on that topic here:

The video is for rules, but the process for creating a new webhook is similar for watchers. Once you create your new webhook, you will need to update the Watch JSON script.

The webhook portion of the script is under:

  "scheme": "https",
  "host": "HOSTNAME",
  "port": 443,
  "method": "post",
  "path": "",
  "params": {}
}

The Webhook string might look something like:

https://prod-43.westus.logic.azure.com:443/workflows/b1f9c72d8e104a3321d85xr7/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=9dfjQwXZr17mbvce62Pna4RuLtKJgWExyiVqA5C

I’ll add line breaks to it’s easier to read:

:443
/workflows/b1f9c72d8e104a3321d85xr7/triggers/manual/paths/invoke
?api-version=2016-06-01
&sp=%2Ftriggers%2Fmanual%2Frun
&sv=1.0
&sig=9dfjQwXZr17mbvce62Pna4RuLtKJgWExyiVqA5C

In this case, your host and webhook would be:

"host":   "prod-43.westus.logic.azure.com",
"port":   443,
"path":   "/workflows/b1f9c72d8e104a3321d85xr7/triggers/manual/paths/invoke",
"params": {
  "api-version": "2016-06-01",
  "sp":          "/triggers/manual/run",
  "sv":          "1.0",
  "sig":         "9dfjQwXZr17mbvce62Pna4RuLtKJgWExyiVqA5C"
}

Finally, I see that this watcher is sending an adaptive card. For adaptive cards to work with the MS Teams Flow:

  • In the Workflows Editor, use the action: Post adaptive card and wait for a response.

  • Post as: Flow Bot

  • Post in: Channel

    • Note: The teams channel used for connectors must be Public.
  • Team: Select desired team

  • Channel: Select desired channel

  • Message:

    • Click the fx button (Expression)
    • paste the following: triggerBody()?['attachments']?[0]?['content']
  • Save

I have also added these instructions for creating a webhook into our Knowledge Base.
I hope this helps!