---
sourceDocument: Australia ServiceNow AI Platform Capabilities
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/servicenow-platform

 Release :

    - australia

ft:locale :

    - de-DE

ft:publication_title :

    - Australia ServiceNow AI Platform Capabilities

ft:clusterId :

    - platcap

bundleId :

    - platcap

workflow :

    - Platform


---

# Execute triggers conditionally

# Execute triggers conditionally {#ariaid-title1}

* Freigeben Version: Australia
* 
* Aktualisiert 12. März 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 Minuten Lesedauer

MetricBase triggers execute
based on a single metric. Condition Scripts impose additional requirements that determine
whether a trigger kicks off a flow.

## Vorbereitungen

Role required: admin

## Warum und wann dieser Vorgang ausgeführt wird

Condition Scripts execute when conditions for a trigger are met but before the
trigger executes a Workflow Studio flow. In that way, Condition Scripts
can prevent triggers from executing flows even when trigger conditions are met. For
example, data often fluctuates over time. Small fluctuations can cause unwanted,
duplicate triggering events. A Condition Script can prevent that erroneous
duplication.

Condition scripts are sometimes also referred to as moderator scripts.

Condition Scripts always return <var class="keyword varname">true</var> (trigger) or
<var class="keyword varname">false</var> (do not trigger). To learn how to write these scripts,
see [Scripting in ServiceNow
Fundamentals](https://www.servicenow.com/services/training-and-certification/scripting-in-servicenow-training.html). To experiment with scripts, see [Get familiar with MetricBase
APIs](https://servicenow-prod.fluidtopics.net/jt6STFYiqfBWXPy4nYjdhg "Experiment with MetricBase APIs using Data Explorer that is part of the MetricBase Demo application. Data Explorer uses the data installed with the MetricBase Demo application.").

## Prozedur

1. Navigate to AllMetricBaseMetricBase TriggersTrigger Condition Script.
2. Select New.
3. On the form, fill in the fields.  
   {#create-action-condition__table_khd_cjn_pbb__entry__2}

   | Field | Description |
   |-|-|
   | Name | Name for the Condition Script. |
   | Application | Scope of the Condition Script. The value, Global, means that the action applies to all applications. |
   | Description | Explanation of what the Condition Script does. When does it return True or False? |
   | Script | Field to enter the JavaScript. Make it returns <var class="keyword varname">true</var> to execute a flow. |
   [ ]

   {#create-action-condition__table_khd_cjn_pbb}
4. Write the Condition Script.  
   When writing a script, think about the conditional statements (what cases it
   should execute for and what cases it shouldn't). If all evaluate
   <var class="keyword varname">true</var>, the script returns <var class="keyword varname">true</var> and
   the flow executes, otherwise it does not. The following example script
   triggers a flow when a drone is traveling too fast at a low altitude
   (defined by level 1). The example shows a typical approach to writing a
   condition script.
   1. Get the trigger definition, passed in as a filter function parameter.
   2. Get the record (<var class="keyword varname">current</var>) that is causing the triggering event, passed in as a filter function parameter.
   3. Get the time from the record that the trigger conditions were satisfied, passed in as a filter function parameter.
   4. Get the trigger level, passed in as a filter function parameter.
   5. Use these parameters to return <var class="keyword varname">true</var> if the level 1 trigger conditions are met and <var class="keyword varname">travel_state</var> equals traveling or speeding.  

          function filter(/*GlideRecord*/ triggerDefinition, /*GlideRecord*/ current, /*GlideDateTime*/ start, /*int*/ level) {
          	// retrieve current travel state of drone
          	var travel_state = String(current.travel_state);
          	
          	// the drone is traveling at a significant speed, and the altitude just went below the threshold 
          	if (((travel_state === 'traveling') || (travel_state === 'speeding')) && (level === 1)){
          		return true; //process this trigger
          	}
          	
          	return false; // don't process this trigger
          }

   {#create-action-condition__substeps_ayb_zn4_pgb}  
   Hinweis:  
   Condition Scripts must execute quickly.
5. Select Submit.

## Nächste Maßnahme

Use Workflow Studio to [associate a flow with a trigger](https://servicenow-prod.fluidtopics.net/vsq69MLtx2Gtg1FT3WVbow "Now that you created a trigger, use Workflow Studio to specify the flow a trigger executes. The flows can provide alerts for unexpected behavior."). When configuring a flow, you can select a Condition Script you created.  
Abbildung : 1. Add a Condition Script to a trigger definition in Workflow Studio

You can also associate a condition script with a trigger flow in the MetricBase Trigger Flows \[sys_flow_metric_trigger\] table. If you
associate a condition script with a trigger flow here, it won't appear in Workflow Studio, but it will still execute with the trigger.
Abbildung : 2. Associate a Condition Script in MetricBase Trigger Flows

