> For the complete documentation index, see [llms.txt](https://docs.flightwatching.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flightwatching.com/user-manual/designer-user-manual/edit-dashboards/dashboards/dashboard-rules/utils.md).

# Utils

## this.sort(k)

On fleet dashboards, this feature allows you to sort the tiles according to k in ascending order.

For example, if you want to sort the dashboards from the ones that have the most alerts to the less (count of alerts is in alertCount):

```javascript
//exemple 1: the count is already computed here
const alertCount = myComputation();
this.sort(-alertCount);

//exemple 2: you have to access some request to count: don't forget the context
const that = this;
WILCO.getEventsStats(FWOT.reg, 
  {
    tags: ['HELLOOOO']
    aggregates: [{kind: "TAG"}]
  }).then(s=>{
    that.sort(-s.HELLOOOO.count)
  });
```

## getTag(tag, event)

If the tag is found in the event, then it is returned (the String, that is equal to the `tag` parameter). Else `null` is returned.

```javascript
if (getTag('IFT_MAIL', EVT)) {
  WILCO.alertInfo("a mail has been sent with along this event")
} else {
  WILCO.alertInfo("no mail sent")
}
```

{% hint style="info" %}
`EVT` is a variable that exists on all the dashboards related to an event. it does not exists on fleet dashboards, for example. But the event could come from another request
{% endhint %}

## setTag(tag, event, toggleTags)

This util sets a `tag` on the current event (but does not push it to the server)

If the `toggleTags` are passed, they are all removed, exept `tag` which is set. It emulates a radio button behavior

## clickForTrend

## updateFwotProperty

## addSamples

Allows to add some samples injected as variables at runtime.

```javascript
    this.addSamples(a.hits.hits.map (h=>{
      return {
        value: "the value",
        name: 'FWPS_L',
        date: moment("1973-01-01")
      };
    })); // FWPS_L will be injected in the rule.
```

```javascript
my_anim.display(FWPS_L); // FWPS_L exists now.
```

## on new messages

Allows to react on new messages, whatever the fwot it is linked on.

onNewMessages takes a function as a parameter that describes the behavior when a new message is sent. You may filter out all the messages that are not related to the current fwot.

{% hint style="info" %}
Historically, it was bulk of events that were passed. Now it is a single event. You can therefore access to the first element of the array, and the array length is 1 only.
{% endhint %}

```javascript
onNewMessages(evts=>{ 
  if (evts[0].reg==EVT.reg) {
    my_anim.go().text(evts[0].title); 
  }
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flightwatching.com/user-manual/designer-user-manual/edit-dashboards/dashboards/dashboard-rules/utils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
