logo

NJP

Fire an event via Flow: Custom Action Guide (Any Table)

Import · May 03, 2022 · article
  1. One action for all tables
  2. Select existing events
  3. Easy to use

Since we fire all our notifications via an event, we have the need to fire events also via "Flows". All research I found was unsatisfactory. It got suggested to create a custom action per table or create a record on the event table. There has also been the request to make this available OOTB (Please upvote).

The main goal of this event is, to be easily and intuitively usable and does what it's supposed to do: Simply fire an event.

Step-by-Step Guide:

  1. Create a new Action
  2. * Action name: "Fire an event"
    • Application: "Global"
    • Accessible From: "All application scopes"
    • Protection: "None"
    • Category:
    • Description:
  3. Create Inputs
  4. 1. * Label: Event Name
    * Name: event_name
    * Type: Reference to Event Registration [sysevent_register]
    * Mandatory: true
    1. * Label: Event Record
      • Name: event_record
      • Type: Document ID
      • * This reference type is the critical part, which the other solutions missed.
        * It allows to drag & drop any kind of record into the field.
      • Mandatory: true
    2. Parm1
    3. * Label: Parm1
      • Name: parm1
      • Type: String
      • Mandatory: false
    4. Parm2
    5. * Label: Parm2
      • Name: parm2
      • Type: String
      • Mandatory: false
  5. Add a new Step
  6. * Script (under Section "Utilities")
    • Required Runtime: Instance
    • Create Input Variables
    • * Name: event_name
      • * Value: Drag "action > Event Name > Event Name" data pill into the field.
      • Name: event_record
      • * Value: Drag "action > Event Record" data pill into the field.
      • Name: parm1
      • * Value: Drag "action > Parm1" data pill into the field.
      • Name: parm2
      • * Value: Drag "action > Parm2" data pill into the field.
    • * (function execute(inputs, outputs) { gs.eventQueue(inputs.event_name, inputs.event_record, inputs.parm1, inputs.parm2); /** If the event_log shows "[object GlideRecord]" as the event name use this instead: gs.eventQueue(inputs.event_name, inputs.event_record, inputs.parm1, inputs.parm2); Thanks to @Monika Bhoyate for pointing it out. */ })(inputs, outputs);
  7. Save & Publish

Usage:

Drag the Action into your flow and use like any scripted event mechanism.

Make sure you only drag records into the the "Event Record" field

image

Any questions? Please let me know.

Simon Ohle

P.S.: Make sure to upvote the OOTB Feature Idea

Labels:

image

View original source

https://www.servicenow.com/community/now-platform-articles/fire-an-event-via-flow-custom-action-guide-any-table/ta-p/2312357