Submit Button is not Working in ESC Provide Feedback

Divya98
Tera Contributor

Provide Feedback.png

When i select feedback choice and click on submit then the feedback is not submitting it is happening in QAT environment were same thing is working in DEV environment can you please help me on this issue.

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Divya98 

Share screenshots and add to post as attachment and not withing the comment.

Also is that an OOTB widget?

Any customization is done to that?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

The Experience feedback modal widget is cloned and done some customizations on CSS styling but not in Client and server script.

api.controller = function($scope, $timeout, $location, $interval, $uibModalStack, snAnalytics) {
    var c = this;
    c.selectedQuestion = "";
    c.enableSubmitButton = false;
    c.positive = false;
    c.negative = false;
    c.suggestion = false;
    c.current = "";
    c.currentQuestionElement = null;
    c.userPreference = false;
    c.isHeaderInMobileView = $rootScope.isHeaderInMobileView;
    c.showHamburger = $rootScope.showHamburger;
    c.showComment = false;
    c.showMandate = false;
    if ((c.data.widgetMode === c.data.WIDGET_MODE_DRAWER && (!c.isHeaderInMobileView && !c.showHamburger))) {
        $scope.$parent.c.calculatePopoverHeight();
    }

    $timeout(function() {
        var modalBody = angular.element('.feedback-modal-footer').closest('.modal-body');
        modalBody.css({
            "padding": "unset",
            "overflow-y": "hidden",
        });
    }, 100);

    c.submit = function() {
        var rating = {
            sentiment: c.current,
            value: c.sentimentValue
        };
        var userPreference = c.data.isAnonymous ? true : angular.element('.user_preference').is(':checked');
        var commentText = c.data.isCommentAllowed ? angular.element('.comment-box').val() : '';
        c.data.questionSentiment = c.current;
        var ratingValue = rating.value || c.ratingSelected;
        c.server.get({
            "action": "submit",
            "rating": ratingValue,
            "userPreference": userPreference,
            "urlParams": $location.search(),
            "additionalComment": commentText,
            "definitionId": c.data.definitionId
        }).then(function(response) {
            if (!response.data.isFeedbackSubmitted)
                return;

            c.data.isSurveyComplete = true;
            c.createAppseeEvent(ratingValue, commentText, userPreference);
            if (c.data.widgetMode === c.data.WIDGET_MODE_DRAWER && !c.isHeaderInMobileView) {
                $('.popover-container').css('height', 'auto');
                $(".feedback-drawer-toggle")[0].innerText = c.data.successText + c.data.successDescription;
                $timeout(function() {
                    $scope.$parent.c.openPopover('click');
                    $timeout(function() {
                        c.data.isSurveyComplete = false;
                        $scope.$parent.c.calculatePopoverHeight();
                    }, 1000)
                }, 1000);
            } else {
                // setting focus to the close icon of the modal
                $('.close.pull-right').focus();
                $(".feedback-modal-toggle")[0].innerText = c.data.successText + c.data.successDescription;
            }
        });
    };

    c.stopTimer = function() {
        $interval.cancel(stop);
    };

    function updateSubmitAndMandateStatus(value) {
        if (c.data.mandate_additional_info === c.data.MANDATE_ADDITIONAL_INFO.optional) {
            setSubmitAndMandate(true, false);
        } else if (c.data.mandate_additional_info === c.data.MANDATE_ADDITIONAL_INFO.rating_based) {
            handleRatingThreshold(value);
        } else {
            setSubmitAndMandate(isCommentProvided(), true);
        }
    }

    // Handle rating threshold logic
    function handleRatingThreshold(value) {
        if (value > c.data.info_comment_threshold) {
            setSubmitAndMandate(true, false);
        } else {
            setSubmitAndMandate(isCommentProvided(), true);
        }
    }

    c.setSelectedQuestion = function($event, selectedQuestion, sentiment, value) {
        c.sentimentValue = value;
        c.selectedQuestion = selectedQuestion;
        c.showComment = true;
        c.current = sentiment;
        c[sentiment] = true;
        $uibModalStack.clearFocusListCache();
        updateSubmitAndMandateStatus(value);
    };

    c.cancel = function() {
        c.enableSubmitButton = false;
        c.selectedQuestion = "";
        c[c.current] = false;
        c.current = "";
        c.showComment = false;
        c.showMandate = false;
        c.sentimentValue = 0;
        c.data.feedback = "";
        c.currentQuestionElement = null;
        if ((c.data.widgetMode === c.data.WIDGET_MODE_DRAWER && (!c.isHeaderInMobileView && !c.showHamburger))) {
            $scope.$parent.c.openPopover('click');
        } else {
            $scope.$parent.$dismiss();
        }
        angular.element('.popover-container').off('keydown', c.focusTrap);
    };

    c.isSelected = function(question) {
        return c.selectedQuestion === question.label ? true : false;
    };

    c.remindMeLater = function() {
        c.server.get({
            "action": "remindMeLater",
        }).then(function(response) {});
        c.cancel();
    };

    c.createAppseeEvent = function(rating, comment, userPreference) {
        var isExperienceSentiment = c.data.ratingType === c.data.experienceRatingType;
        var feedbackName = isExperienceSentiment ? c.data.feedbackTypeName : c.data.feedbackRatingTypeName;
        var ratingValue = isExperienceSentiment ? c.selectedQuestion : rating;
        var userStatus = userPreference ? "${Anonymous}" : "${Non - Anonymous}";

        var payload = {
            name: feedbackName,
            data: {
                Rating: ratingValue,
                Users: userStatus
            }
        };

        if (comment) {
            payload.data.Comment = c.getCommentsGroupByValue(rating, c.data.ratingType);
        }

        snAnalytics.addEvent(payload);
    };

    c.getCommentsGroupByValue = function(ratingValue, ratingType) {
        var comments = {
            sentiment: {
                5: "${Like}",
                3: "${Suggestion}",
                1: "${Don't Like}"
            },
            rating: {
                5: "${Very good}",
                4: "${Good}",
                3: "${Average}",
                2: "${Bad}",
                1: "${Very bad}"
            }
        };

        var group = (ratingType === c.data.experienceRatingType) ? 'sentiment' : 'rating';

        return comments[group][ratingValue] || null;
    };

    c.keydownEventHandler = function(event, index, question) {
        var newQuestion;

        switch (event.key) {
            case 'ArrowUp':
            case 'ArrowLeft':
                newQuestion = (index - 1 < 0) ? c.data.questionsList[c.data.questionsList.length - 1] : c.data.questionsList[index - 1];
                break;

            case 'ArrowDown':
            case 'ArrowRight':
                newQuestion = (index + 1 >= c.data.questionsList.length) ? c.data.questionsList[0] : c.data.questionsList[index + 1];
                break;

            default:
                return;
        }

        c.setSelectedQuestion(event, newQuestion.label, newQuestion.sentiment, newQuestion.value);
        var feedbackButton = '.btn-feedback-' + newQuestion.sentiment;
        $(feedbackButton).focus();

        event.preventDefault();
    };
    // focus trap is lost when content inside the modal changes hence manually handling
    $('.close.pull-right').on('keydown', function(e) {
        if (e.keyCode == 9 && c.data.isSurveyComplete) {
            e.preventDefault();
            $('.close.pull-right').focus();
        }
    });

    c.onTextAreaKeyPress = function(val) {
        var ratingValue = c.sentimentValue || c.ratingSelected;
        if (shouldMandateAdditionalInfo(ratingValue)) {
            c.enableSubmitButton = val.trim().length > 0;
        } else {
            c.enableSubmitButton = true;
        }
    };

    // Determine if additional info is mandatory based on the rating value
    function shouldMandateAdditionalInfo(ratingValue) {
        return c.data.mandate_additional_info === c.data.MANDATE_ADDITIONAL_INFO.mandatory ||
            (c.data.mandate_additional_info === c.data.MANDATE_ADDITIONAL_INFO.rating_based && ratingValue <= parseInt(c.data.info_comment_threshold));
    }

    // Check if a comment has been provided
    function isCommentProvided() {
        var comment = angular.element('.comment-box').val();
        return comment && comment.trim().length > 0;
    }

    // Set submit button state and mandate visibility
    function setSubmitAndMandate(enableSubmit, showMandate) {
        c.enableSubmitButton = enableSubmit;
        c.showMandate = showMandate;
    }

    // Event listener for rating selection change
    $scope.$on(c.data.ratingSelectedEvent, function($event, data, val) {
        c.data.hasActiveSelection = data;
        c.ratingSelected = val;

        if (!c.ratingSelected) {
            c.showComment = false;
            setSubmitAndMandate(false, false);
        } else {
            c.showComment = true;
            updateSubmitAndMandateStatus(c.ratingSelected);
        }
        $event.stopPropagation();
    });


};

 

@Divya98 

any browser errors when Submit is clicked?

Since it's customized you will have to debug by adding logs or alert.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader