Alternative for Client UI Actions in Service Portal

HV1
Mega Guru

Helsinki Service Portal does not support Client marked UI Actions. We have UI Actions on Incident form on click of which certain fields should turn mandatory on form and check for data. If the data is filled, then go ahead with server action.   We are displaying incidents on Service Portal in Form Widget. How do we replicate this behavior when working on Incident records in Service Portal Form Widget?

1 ACCEPTED SOLUTION

HI Hardik,



Honestly at the time of my reply I did not thought about that point. But I did a quick search in the documentation and it is actually pretty simple, you can use: g_form.getActionName(), which will return your UI Action name so you can make a condition based on that name.


View solution in original post

7 REPLIES 7

First you should make sure that your client script UI Type is set to both.



Here is an example of a script working in both UI:



function onSubmit() {


  //Type appropriate comment here, and begin script below


  if(g_form.getActionName() == 'test_update'){


  return confirm('Do you confirm?');


  }


}


Thanks Laurent for quick reply! Issue is with my client script UI Type which is not set to both.



Thanks for your assistance!



Can you help me on other thing?



UI Action is "Delete" which is visible on service portal form. If we click on "Delete", current record will be deleted (after confirmation) and should redirect to previous page in service portal or list page in service portal.



Could you please help me how can we set redirection in UI Action (which works in service portal form)? or any other way to handle this scenario (after deleting record, redirection should be to previous page or some desired list page in service portal)?


Hi Pavan,



To do this, you will have to modify the form widget (clone it and modify), then you place the cloned widget on your form page to replace the OOTB one. As action.setRedirectURL does not work in service portal, it is the only option that I'm aware.



To do it you will need to modify 2 functions of the client controller:



$scope.triggerUIAction = function(action) {


  if ($scope.data.disableUIActions)


            return;



  if (g_form) {


            $timeout(function() {


                      if(action.action_name == 'sysverb_delete'){


                                $scope.isDelete = true;


                      }


                      g_form.submit(action.action_name || action.sys_id);


            });


  }


}



The modification is to check for the action_name sysverb_delete, you can set another name if you used a differennt name. If it is your delete we set that value in the $scope for later use.



$scope.$on("spModel.uiActionComplete", function(evt, response) {


  if($scope.isDelete){


            $location.url($location.path()); // Reset the url parameters


            $location.search('id', 'list');


            $location.search('table', $scope.data.f.table);


  }


  else{


            var sysID = (response.isInsert) ? response.sys_id : $scope.data.sys_id;


            loadForm($scope.data.table, sysID).then(constructResponseHandler(response));


  }


});



The modification is that we check if the action executed was delete and if it was, we rediect the user to the list view of the current table. You might want to add additionnal parameters for the query of the list. Otherwise the original script is runned.



If you wanted to redirect to the previous page instead of the 3 $location line, you would use: $window.history.back();