Reject button in custom Service Portal widget not recognizing textarea input

Puneet Hegde1
Tera Guru

Hi everyone,

I'm building a custom Service Portal widget that allows users to either accept or reject a proposed solution on an incident record when it's in the Resolved state.

The "Accept Solution" button works perfectly and updates the incident state to Closed.
However, when clicking the "Reject Solution" button, a modal pops up with a textarea for the user to enter a rejection reason. The form has a submit button which should call submitRejection().

Here’s the issue:

Even after entering text into the textarea, the script always thinks the comment is empty. It keeps showing the alert:

"Please enter a reason for rejection."

 

Please find the blow client script in widget is where i'm having problem:

function($scope) {
$scope.showModal = false;
$scope.rejectionReason = '';

// Accept Solution (unchanged)
$scope.acceptSolution = function() {
var ga = new GlideAjax('SolutionFeedbackHandler');
ga.addParam('sysparm_name', 'processFeedback');
ga.addParam('sysparm_incident_id', $scope.data.sys_id);
ga.addParam('sysparm_action', 'accept');
ga.addParam('sysparm_comment', ''); // Empty for accept

ga.getXMLAnswer(function(response) {
if (response === 'success') {
$scope.$apply(function() {
$scope.data.message = "Thank you! The incident is now closed.";
$scope.data.actionTaken = true;
});
} else {
alert("Failed: " + response);
}
});
};

// Open Reject Modal
$scope.showRejectModal = function() {
$scope.rejectionReason = '';
$scope.showModal = true;
};

// Close Reject Modal
$scope.closeModal = function() {
$scope.rejectionReason = '';
$scope.showModal = false;
};

// Force model sync on change
$scope.updateRejectionReason = function() {
if (!$scope.$$phase) {
$scope.$apply();
}
};

// Submit Rejection
$scope.submitRejection = function() {
var comment = ($scope.rejectionReason || '').trim();

console.log("DEBUG: rejectionReason = [" + comment + "]");

if (!comment) {
alert("Please enter a reason for rejection.");
return;
}

var ga = new GlideAjax('SolutionFeedbackHandler');
ga.addParam('sysparm_name', 'processFeedback');
ga.addParam('sysparm_incident_id', $scope.data.sys_id);
ga.addParam('sysparm_action', 'reject');
ga.addParam('sysparm_comment', comment);

ga.getXMLAnswer(function(response) {
if (response === 'success') {
$scope.$apply(function() {
$scope.data.message = "Thanks! The incident has been reopened.";
$scope.data.actionTaken = true;
$scope.showModal = false;
});
} else {
alert("Failed: " + response);
}
});
};
}