Part 20: Understand Mutation Data broker events

Understand event for Create Record Data broker

Let’s take following snippet from the last post

if (event.elementId == "create_record_1") {

        var items = [];
        var requestFailed = false;
        if (event.name == "DATA_OP_SUCCEEDED") {
            var output = event.payload.data.output.data.GlideRecord_Mutation.insert_kb_feedback;
            if (output == null) {
                requestFailed = true;
            } else {

                items.push({
                    id: "ratingArticleSuccess",
                    status: "info",
                    icon: "info-circle-outline",
                    content: "Feedback submitted.",
                    action: {
                        type: "dismiss"
                    }
                });
            }
        }
  • Typically, we have created an event handler client script which manages the event
  • The very first line talks about the element for which the event is triggered
  • Since the ID of the data broker is “create_record_1” we are checking if the element ID matches
  • Line 3 is where we are building the empty items object for the event we emits for the message to appear NOW_UXF_PAGE#ADD_NOTIFICATIONS
  • Lint 5 iswhere we are saying which specific event from that element we care about. This will be used when we try handle multiple event for the same element.

Use Debugger to know how did we get Line 6

  • Add a debugger after line 5
if (event.name == "DATA_OP_SUCCEEDED") {
    debugger;
    var output = event.payload.data.output.data.GlideRecord_Mutation.insert_kb_feedback;
}
  • This is how Line 6 is generated in the above code snippet
  • Following code snippet is what makes message appear on the screen
if (items.length > 0) {
    emit("NOW_UXF_PAGE#ADD_NOTIFICATIONS", {
        items
    });
}

Great!! We have learnt how to debug the event and find out what we need from the event object.

Leave a comment