Akash Rajput Technology over a cup of coffee

Part 20: Understand Mutation Data broker events

1 min read

Featured Video Play Icon

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 that 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 emit for the message to appear NOW_UXF_PAGE#ADD_NOTIFICATIONS
  • Lint 5 is where we are saying which specific event from that element we care about. This will be used when we try to handle multiple events 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;
}
  • Navigate to the page
    https://<instance-name>.service-now.com/now/panda_tech/knowledge-article/params/sys-id/f27d7f79c0a8011b0018f9d700d2b9aa
  • Goto Browser Console from Inspect Element
  • Give some ratings to the article
  • Watch for debugger as it stops the execution
  • Type Event in the console and hit Enter
  • 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 &gt; 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.

Akash Rajput Technology over a cup of coffee

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss a story from me, get updates directly in your inbox.
Loading