Akash Rajput Technology over a cup of coffee

Part 18: Add event to save ratings

48 sec read

Featured Video Play Icon

Add Event handler once the record is saved in kb_feedback table

  • Goto Data Resources
  • Select Create Record 1
  • Goto Events Section
  • Expand Operation Succeeded event (This will be triggered after successful DB operation)
  • Click Add New Event Handler
  • Select Handler Star rating from the scripts section
  • Click Save

Update the Script to handle Operation Succeeded event

  • Goto Page Scripts
  • Open Handler Star rating Script
  • Append the following snippet
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"
                    }
                });
            }
        }

        if (event.name == "DATA_OP_FAILED" || requestFailed) {
            items.push({
                id: "flagArticleFailure",
                status: "critical",
                icon: "info-circle-outline",
                content: "Technical issue submitting a feedback. Try again later",
                action: {
                    type: "dismiss"
                }
            });
        }
        
        if (items.length > 0) {
            emit("NOW_UXF_PAGE#ADD_NOTIFICATIONS", {
                items
            });
        }
    }

Note: In the next post, We will walk through the entire code to understand how exactly this works. You should see a feedback text once you select the star rating

Great!! We have successfully added a confirmation message on feedback submission rating to the kb_feedback table

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