# Query Message and Trigger an Action

**URL:** https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461
**Category:** General
**Created:** [28 February 2019 09:11 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461 "2019-02-28T09:11:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ebnerjoh](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ebnerjoh](https://discourse.nodered.org/u/ebnerjoh)
#### Post date: [28 February 2019 09:11 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/1 "2019-02-28T09:11:44Z")

</div>

Hi,

I am getting from an API Integration a long message payload:

`{"customerId":"xxx","customerName":"xxx","username":"xxx","userId":"xxx","settings":{"type":"ALARM_ONLY","version":"CUSTOM","screenSaverVersion":"NO_SCREEN_SAVER","recipientsType":"ALL","participantSortOrder":"NN_VN_COMMENT","mapType":"HYBRID","screenSaverTimeout":120,"defaultMapZoomFactor":13,"defaultMapLongitude":null,"defaultMapLatitude":null,"showFunctions":true,"showMultipleAlarms":false,"customLayout":"{\"layout\":\"SINGLE\",\"tiles\":[{\"urlExtra\":\"?Bereich=all\",\"provider\":\"zamg\",\"province\":\"\",\"hideTitle\":true,\"showFunctions\":false,\"mapType\":\"terrestris\",\"showOfm\":false,\"showRoute\":false,\"recipientsType\":\"ALL\",\"zoomLevel\":17,\"maxWasserkarteItems\":50,\"type\":\"last-alarm-text\"}],\"showHeader\":false}","customScreenSaverLayout":"{\"layout\":\"DUAL_VERTICAL\",\"tiles\":[{\"urlExtra\":\"?Bereich=all\",\"provider\":\"zamg\",\"province\":\"\",\"hideTitle\":true,\"showFunctions\":false,\"mapType\":\"terrestris\",\"showOfm\":false,\"showRoute\":false,\"recipientsType\":\"ALL\",\"zoomLevel\":17,\"maxWasserkarteItems\":50,\"type\":\"future-alarms\"},{\"urlExtra\":\"?Bereich=all\",\"provider\":\"zamg\",\"province\":\"\",\"hideTitle\":true,\"showFunctions\":false,\"mapType\":\"terrestris\",\"showOfm\":false,\"showRoute\":false,\"recipientsType\":\"ALL\",\"zoomLevel\":17,\"maxWasserkarteItems\":50,\"type\":\"blackboard\"}],\"showHeader\":true}","defaultMapCoordinates":null,"printingEnabled":false},"customerLocation":{"administrativeArea":"Kärnten","latitude":46.9801471,"longitude":14.2123172,"southBoundLatitude":46.9256805,"northBoundLatitude":47.0585828,"westBoundLongitude":14.0119019,"eastBoundLongitude":14.2648153},"integrations":[],"alarms":[{"productType":"BLAULICHT","customerId":"xxx","alarmId":"995c1b40-56b7-46f5-8653-22e05f86714a","scenarioId":null,"indexNumber":78973,"alarmGroups":[{ **"groupId":"G1","groupName":"Sirenenalarm"** }],"alarmDate":"2019-02-03T15:21:02.020Z","endDate":"2019-02-04T15:21:02.020Z","authorName":"LAWZ Klagenfurt","alarmText":"Sirenenalarm (Techn.Einsatz/AST1) für Metnitz:\nEO Unteralpe 18,\nGDE Metnitz 16:20","audioUrl":null,"needsAcknowledgement":true,"usersAlertedCount":44,"geolocation":{"coordinates":{"lat":46.97994689999999,"lon":14.1689192},"positionSetByAuthor":false,"radius":50,"distance":5122,"duration":7,"address":"Unteralpe 18, 9363, Österreich"},"coordinates":{"lat":46.97994689999999,"lon":14.1689192},"recipients":[{xxx}],"futureAlarms":[{"productType":"BLAULICHT","customerId":"xxx","alarmId":"xxx","scenarioId":null,"indexNumber":null,"alarmGroups":[],"alarmDate":"2019-03-08T18:30:00.000Z","endDate":"2019-03-08T18:30:00.000Z","authorName":"xxx","alarmText":"Termin am 08.03.2019 19:30 - Vollversammlung","audioUrl":null,"needsAcknowledgement":false,"usersAlertedCount":0,"geolocation":{"coordinates":null,"positionSetByAuthor":false,"radius":null,"distance":null,"duration":null,"address":null},"coordinates":null,"recipients":[],"pointsOfInterest":[]}],"blackboard":{"content":null,"lastUpdateDate":null,"lastUpdateAuthorId":null}}`

Inside this Message you will find the following Information:

`[{ **"groupId":"G1","groupName":"Sirenenalarm"** }]`

I want to trigger an Action when "groupName" is either "Sirenenalarm" or "Stiller Alarm".

How could I achive this?

Br,  
Johannes

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 February 2019 09:32 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/2 "2019-02-28T09:32:39Z")

</div>

You can use a Switch node to examine the contents of the particular property you are interested in and only pass on a message if it matches the values you are interested in.

The first step is to identify the full path to the property you want - you can use the Debug sidebar to help you do that.

[https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message](https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 February 2019 09:39 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/3 "2019-02-28T09:39:46Z")

</div>

errr. is `{**"groupId":"G1",` valid JSON ? or is that something you have added to try to add markdown for emphasis here ?

---

<div class="post-metadata">

### Author: ![ebnerjoh](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ebnerjoh](https://discourse.nodered.org/u/ebnerjoh)
#### Post date: [28 February 2019 10:06 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/4 "2019-02-28T10:06:09Z")

</div>

Hi, I think it was a Copy/PAste error

"alarmGroups":[{"groupId":"G1","groupName":"Sirenenalarm"}],

---

<div class="post-metadata">

### Author: ![ebnerjoh](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ebnerjoh](https://discourse.nodered.org/u/ebnerjoh)
#### Post date: [28 February 2019 11:25 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/5 "2019-02-28T11:25:15Z")

</div>

Hi,

Ok, I got it now working.

I have now only one issue. The API is only receiving a new message when there is an update. Every reload/restart is recogniced as an update so I will get one message, although it might be old.

I have now one idea. The Alarm included also a timestamp:

payload.alarms[0].alarmDate  
2019-02-03T15:21:02.020Z

I am thinking of taking this timestamp and block the message if it is older then 5 minutes.The question is how I could achive this?

Br,  
JOhannes

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 February 2019 11:35 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/6 "2019-02-28T11:35:32Z")

</div>

> [@ebnerjoh](#):
>
> I am thinking of taking this timestamp and block the message if it is older then 5 minutes.The question is how I could achive this?

In a Function node you can do something like:

```auto
var alarmDate = new Date(msg.payload.alarms[0].alarmDate);
var now = Date.now();
var delta = now - alarmDate.getTime();
if (delta > (1000 * 60 * 5)) {
    // the gap is greater than 5 minutes (in milliseconds)
    // don't pass on the message
    return null;
}
return msg;

```

---

<div class="post-metadata">

### Author: ![ebnerjoh](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ebnerjoh](https://discourse.nodered.org/u/ebnerjoh)
#### Post date: [28 February 2019 13:23 UTC](https://discourse.nodered.org/t/query-message-and-trigger-an-action/8461/7 "2019-02-28T13:23:17Z")

</div>

Many thanks, works as expected!

Br,  
Johannes
