Adding a button to the Portal - to set the value of a 'true/false' field in an HR Case

Carl Fransen1
Tera Guru

Hi Team,

I have a custom 'true/false' field called 'u_re_approval' which works with my workflow to send the HR Case for another round of approvals if rejected.  All this works great, except I need the employee to also be able to update the field via the HR Portal interface.

The Page I updated is 'hrj_ticket_page' pointing to the widget 'hrj-case-info' and the button shows up all fine, but I can't get the code working correctly to set the value of this field to 'true'.  I think it's the client and server code that isn't working and now sure why, any help is appreciated.

Widget HTML:

<button name="reapproval" class="btn btn-primary" style="margin-bottom: 20px" ng-click="reapprove();">Send for Re-Approval</button>

The above seems to work as the button is showing and when I press it the client statement console.log shows the current value.

Server Code:

// CJF 23-07-18 New server function for 'Send for Re-Approval' button for HR Training
	function(){	
	// Send for Re-Approval
		if (input && input.action){
			var action = input.action;
			if (action == 'reapprove'){
				grCase.setValue('u_re_approve2', true);
				grCase.update();
			}
		}
	}
	//CJF 23-07-18 - End of new function

Client Code:

// CJF 23-07-18
	$scope.reapprove = function() {
		console.log($scope.data.reApproval);
		//$scope.data.reApproval = true;
	//data.reApproval = grCase.getDisplayValue('u_re_approval');
	$scope.server.update();
					c.server.update().then(function(){
				//$scope.update();
		})
		}

Hopefully it's only something simple...

Cheers

Carl.

1 ACCEPTED SOLUTION

Try updating you script with below and check.

(function() {
 
	gr = new GlideRecord('sn_hr_core_case');
        gr.get(,$sp.getParameter('sys_id'));

	if (input && input.action) {
		var action = input.action;
 
	if (action == 'reapprove') {
				// Re-approve HR Case
				gr.setValue('u_re_approve2', true);
				gr.update();
			}
			//if (action == 'cancel') {
			//	// Do something else
		//	}
		}
})();

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

18 REPLIES 18

Ok...I would suggest use the UI action. That is much more easy, since you just want to set a field and not perform any client action. Create a UI action on you table and add your script instead of modifying the widget


Please mark this response as correct or helpful if it assisted you with your question.

OK that sounds good - just not sure how I would be able to add a UI Action to my portal page and have it accessible form the hrj ticket page.

 

Are you able to help with this?

When you add a UI action on the table, it should automatically appear on the form.

I dont have access to that page right now, since I dont have HR plugin activated.

 

 


Please mark this response as correct or helpful if it assisted you with your question.

A UI Action only works that way on the client side of ServiceNow, I need this to work on the portal, so it's definitely a widget mod that is required...

A UI action also works on portal. Because I have created myself lot of Server UI action which works fine on Portals. 

 

But Since I am not sure what are you displaying on the portal, I would ask you to try both. If it is a form widget, it should ideally show all the UI actions as well


Please mark this response as correct or helpful if it assisted you with your question.