How to make Reject comments mandatory for approval records in service portal

venkata satish
Tera Expert

Hi All,

We have a requirement to make reject comments mandatory in Service portal.

 In Approvals page(below screen shot) when user clicks on Reject button it should popup a window to capture reject reason/comments. Please let me know if there is any widget available.

 

find_real_file.png

Regards,

Venkata Satish

1 ACCEPTED SOLUTION

ChrisCooke
Giga Contributor

Firstly you will need to copy the approvals widget.

Add in spModal directive:

function ($scope, spUtil, spUIActionsExecuter, spModal) 

Then you will need to modify the reject function in the client script something like this:

$scope.reject = function(id, esigRequired) {
		
		spModal.open({
			title: 'Reject Approval',
			message: 'Please enter your reason for rejection, note this will be communicated with the requestor',
			input: true,
			value: $scope.name
		}).then(function(name) {
			$scope.name = name;
			
			var requestParams = {
				username: $scope.data.esignature.username,
				userSysId: $scope.data.esignature.userSysId
			};
			
			if($scope.data.esignature.e_sig_required && esigRequired) {
				spUIActionsExecuter.executeFormAction(ESIGNATURE.REJECT_SYS, "sysapproval_approver" , id, [] , "", requestParams).then(function(response) {
				});
			} else {
				$scope.data.op = "rejected";
				$scope.data.target = id;
				$scope.data.reject_comment = "Rejection reason: " + $scope.name;
				get();
			}
		});
	};

 

Then you will need to update the input on the server script something like this:

if (input) {
	// update pagination
	currentPage = input.pagination.currentPage;
	initRow = (currentPage * maxNumberOfItemsInTheList);
	lastRow = initRow + maxNumberOfItemsInTheList;
	
	if (input.op == 'approved' || input.op == 'rejected') {
		var app = new GlideRecord("sysapproval_approver");
		if (app.get(input.target) && app.state.canWrite()) {
			app.state = input.op;
			if(input.op == 'rejected')
			{
				app.comments = input.reject_comment;
			}
			app.update();
		}
	}
}

 

Hope this helps,

Chris

View solution in original post

2 REPLIES 2

ChrisCooke
Giga Contributor

Firstly you will need to copy the approvals widget.

Add in spModal directive:

function ($scope, spUtil, spUIActionsExecuter, spModal) 

Then you will need to modify the reject function in the client script something like this:

$scope.reject = function(id, esigRequired) {
		
		spModal.open({
			title: 'Reject Approval',
			message: 'Please enter your reason for rejection, note this will be communicated with the requestor',
			input: true,
			value: $scope.name
		}).then(function(name) {
			$scope.name = name;
			
			var requestParams = {
				username: $scope.data.esignature.username,
				userSysId: $scope.data.esignature.userSysId
			};
			
			if($scope.data.esignature.e_sig_required && esigRequired) {
				spUIActionsExecuter.executeFormAction(ESIGNATURE.REJECT_SYS, "sysapproval_approver" , id, [] , "", requestParams).then(function(response) {
				});
			} else {
				$scope.data.op = "rejected";
				$scope.data.target = id;
				$scope.data.reject_comment = "Rejection reason: " + $scope.name;
				get();
			}
		});
	};

 

Then you will need to update the input on the server script something like this:

if (input) {
	// update pagination
	currentPage = input.pagination.currentPage;
	initRow = (currentPage * maxNumberOfItemsInTheList);
	lastRow = initRow + maxNumberOfItemsInTheList;
	
	if (input.op == 'approved' || input.op == 'rejected') {
		var app = new GlideRecord("sysapproval_approver");
		if (app.get(input.target) && app.state.canWrite()) {
			app.state = input.op;
			if(input.op == 'rejected')
			{
				app.comments = input.reject_comment;
			}
			app.update();
		}
	}
}

 

Hope this helps,

Chris

@chris : This is working perfect. Thank you very much.