Service Portal Form Widget - Create new UI Action

Bianca1
Giga Contributor

Is it possible to create a new UI Action for a cloned Form Widget that will not check for the canWrite() function? 

The OOB widget requires GlideRecordSecure, however we are trying to handle write access separately.

1 ACCEPTED SOLUTION

Basically, yes.

Here is what I have done:

Inside my cloned form widget, I modified the $scope.getPrimaryAction function to get the Purple UI Action I created, here is the code:

$scope.getPrimaryAction = function() {
		var primaryActions = $scope.data.f._ui_actions.filter(function(action) {
        if(action.action_name == "iap_app_save") {
            return action;
        }
    });
    return primaryActions;
	}

Below is the $scope.data object showing where I got the Purple UI Action (purple box). You can also see below that the Blue UI Action(blue box) is stored in the same _ui_actions array:
find_real_file.png

I thought this would work (the Blue save button appears on the form) however, it is not saving and  I am getting the error:

Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"getPrimaryAction()","newVal":[{"sys_id":"ee26259a204080940221e6e73fc108ac","is_link":false,"action_name":"iap_app_save","name":"Save ","is_button":true,"is_context":false}],"oldVal":["..."]}],[{"msg":"getPrimaryAction()","newVal":["..."],"oldVal":"..."}],[{"msg":"getPrimaryAction()","newVal":["..."],"oldVal":"..."}],[{"msg":"getPrimaryAction()","newVal":["..."],"oldVal":"..."}],[{"msg":"getPrimaryAction()","newVal":["..."],"oldVal":"..."}]]
http://errors.angularjs.org/1.5.11/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22msg%22%3A%22getPrimaryAction()%22%2C%22newVal%22%3A%5B%7B%22sys_id%22%3A%22ee26259a204080940221e6e73fc108ac%22%2C%22is_link%22%3Afalse%2C%22action_name%22%3A%22iap_app_save%22%2C%22name%22%3A%22Save%20%22%2C%22is_button%22%3Atrue%2C%22is_context%22%3Afalse%7D%5D%2C%22oldVal%22%3A%5B%22...%22%5D%7D%5D%2C%5B%7B%22msg%22%3A%22getPrimaryAction()%22%2C%22newVal%22%3A%5B%22...%22%5D%2C%22oldVal%22%3A%22...%22%7D%5D%2C%5B%7B%22msg%22%3A%22getPrimaryAction()%22%2C%22newVal%22%3A%5B%22...%22%5D%2C%22oldVal%22%3A%22...%22%7D%5D%2C%5B%7B%22msg%22%3A%22getPrimaryAction()%22%2C%22newVal%22%3A%5B%22...%22%5D%2C%22oldVal%22%3A%22...%22%7D%5D%2C%5B%7B%22msg%22%3A%22getPrimaryAction()%22%2C%22newVal%22%3A%5B%22...%22%5D%2C%22oldVal%22%3A%22...%22%7D%5D%5D
    at js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:6416
    at Scope.$digest (js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:14750)
    at ChildScope.$apply (js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:14816)
    at HTMLLIElement.<anonymous> (js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:67080)
    at HTMLLIElement.dispatch (js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:3003)
    at HTMLLIElement.elemData.handle (js_includes_sp.jsx?v=11-11-2018_0542&lp=Mon_Jul_08_20_42_23_PDT_2019&c=34_400:2877)

Link to AngularJS

Any idea of what I am doing wrong?

 

Thanks,

Bianca

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

Your question is a little unclear, are you trying to remove canWrite() from 

A. A cloned widget

or

B. A UI Action

 

If you are doing it from the cloned form widget, I don't see why you couldn't change 

data.canWrite = rec.canWrite();
var hasRecordAccess = data.sys_id == "-1" ? rec.canCreate() : data.canWrite;

to

var hasRecordAccess = data.sys_id == "-1" ? rec.canCreate() : true;

if you are handling write access elsewhere.

 

If this is indeed not the place you were looking at, please provide a clearer path to what you are trying to change so we can assist.

Thanks

Hi Aidan,

 

Thank you for the response. Sorry if it was unclear, I did not completely understand at first either. I figured out how to create a UI Action and add to the form.. however, I do not want to use the basic UI Actions, I want to use the Blue Service Portal Save button.. Explained below:
find_real_file.png
The red button: Servicenow generic save button. I do not want to use this because it checks canWrite()
The purple button: Custom Save button that I created that does not have any conditions and just updates the record
The blue button: Want to use this button, but believe it functions the same as red. 

Is there a way to redirect the blue button to use the purple UI Action?

 

Also, is what I am trying to do achieved by your solution stated above?

Community Alums
Not applicable

Just for clarification, you want to use the purple button, but you want it to look like the blue button ?

Basically yes. 


This HTML for the Blue button calls triggerUIAction(getPrimaryAction()), is it possible to trigger the purple UI Action instead?

<button ng-if="getPrimaryAction()" type="submit" ng-click="triggerUIAction(getPrimaryAction())" ng-disabled="submitting" class="btn btn-primary action-btn pull-right" gsft_id="{{::getPrimaryAction().sys_id ? getPrimaryAction().sys_id : ''}}">${Save} <span ng-if="saveButtonSuffix">(${{{saveButtonSuffix}}})</span></button>