
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2018 10:26 PM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 07:20 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 03:24 PM
Hi Sanjiv,
Yes you are right, what I meant was that the buttons automatically appear in the client side when adding for a table, but not automatically in the portal - I have seen UI actions work on the portal - like this link from Nathan:
https://serviceportal.io/create-custom-action-buttons-service-portal/
However this is a new widget and I need to emulate this in my existing ticket page. It doesn't matter if its an Incident or HR CAse, essentially all I want to achieve is to be able to set a 'true/false' field to 'true' by pressing a button on the portal that is inside the ticket page, not a separate widget.
Thanks Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 12:31 PM
Hi Carl,
you are missing this line in your client script function.
$scope.data.action ='reapprove';
Also in server script, make sure it has reference to grCase. In other words it must be defined somewhere above your server script code where you checking for this action and setting your value.
Let me know how it goes.
Please mark Correct/Helpful if it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 02:08 PM
Hi,
Please try adding above line, you have almost completed your functionality,so you dont need UI action in this case and even if you add one, it wont show up on portal view.
Hope that helps.
Please mark Correct/Helpful if it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 02:38 PM
Thanks for the help. I added the line but it's still not working, but not sure I added it to the right place - see below:
// CJF 23-07-18
$scope.reapprove = function() {
console.log($scope.data.reApproval);
$scope.server.update();
c.server.update().then(function(){
$scope.data.action = 'reapprove';
//$scope.update();
})
}
I also tried adding it under the 'console.log' but this also didn't work.
The grCase was defined at the top of the server script, but it may not be available in my new function, so I have updated it to add as per below:
// CJF 23-07-18 New server function for 'Send for Re-Approval' button for HR Training
function(){
var gr = new GlideRecord('sn_hr_core_case');
// Send for Re-Approval
if (action == 'reapprove'){
gr.setValue('u_re_approve2', true);
gr.update();
}
}
//CJF 23-07-18 - End of new function
But it's still not working - there is no update going back to the HR Case so the field is not being updated.
Hoping you can help further.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 05:37 PM
Hi All,
After investigating things a bit further I've decided on a slightly different approach - to leave the original ticket form and to add a second column to hold a new widget. This will look cleaner and mean the page is left 'as is'. I have based this on the code provided by Nathan below:
https://serviceportal.io/create-custom-action-buttons-service-portal/
However I've updated it slightly for the HR Core table (sn_hr_core_case). My new form looks like the below:
But when I load my page I receive the following errors:
It seems not to like the 'table' from the server code, but from all the examples I've seen on the community this works fine for the likes of Incident. I have created the widget in the 'HR Service Portal' scope -
Can anyone help figure out why this error is appearing?
Thanks
Carl.