Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Add a custom field to Todos HR Case Approval widget

Padraig O_Kane1
Tera Contributor

I have a requirement to introduce a Second Approver field on the HR Case Approval widget that is then passed to the Approval record and updated. I have cloned the out of the box widget and made the following changes (see screenshot 1 where I have introduced the new field, server logic to pull back a list of users and broadcast logic to check for changes to the field - this is needed as the widget relies on an embedded widget where the Approve/Reject buttons are located). The issue I am having is passing the new field value to the embedded widget (see screenshot 2 where I have introduced a listener for field changes). I have also made changes to the script include but whenever I log the secondApprover value it is empty or doesn't appear in the request output). Any help would be great. 

1 REPLY 1

KPNow
Tera Expert

The probable reason your secondApprover value is coming up empty is perhaps due to an asynchronous timing issue in your embedded widget's client script specifically, you are defining the $scope.$on('data-updated') listener inside your sendUpdateRequest() function right before creating c.data.request. Because $scope.$on sets up an event listener for future broadcasts rather than executing synchronously on the spot, c.data.secondApproverremains undefined when c.server.update() fires. To fix this, move the $scope.$on('data-updated', ...) listener out of sendUpdateRequest to the top level of your embedded widget's client controller so it constantly listens for changes, update your broadcast in the parent widget to pass an object like $rootScope.$broadcast('data-updated', { secondApprover: $scope.data.secondApprover }), and then extract input.request.secondApproveron the server script before handing it off to your Script Include.

Hope this helps.