How to change Save button functionality of Form widget without cloning

yundlu316
Kilo Guru

Our team wants our portal page to stay out of the box as much as possible, and after reading this article on serviceporal.io, it seems like it's possible through a couple different ways.  We want to change the functionality of the "Save" button on the ootb Form widget and it looks like that may be possible without cloning by creating a directive.  Our team has never created a directive before and really unsure how to start.  For this example, if we wanted the Save button to throw up a confirmation message box before submission, how can we achieve this through a directive and without cloning?

3 REPLIES 3

Ishita Shrivast
Kilo Guru

Hey there,

Try this code.

// HTML template 
 <button ng-click="c.onConfirm()" class="btn btn-default"> Confirm </button> 
<span>{{c.confirmed}}</span>   

// Client script
function(spModal) {
  var c = this;
  c.onConfirm = function() {
        c.confirmed = "asking";
        spModal.confirm("Can you confirm or deny this?").then(function(confirmed) {
            c.confirmed = confirmed; // true or false
        })
    }
 } 



For more details, check this below link

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

If this helps, please mark it as correct and helpful.

Thanks and regards,

Ishita Shrivastava

Oleg
Mega Sage

Could you describe more detailed what kind of changes in functionality of "Save" button you need to implement? Do you want to implement the changes on saving of records of specific tables on on saving all tables? Do you need to make the changes on the server-side functionality of the "Save" button or on the client-side behavior?

In general, ob click on "Save" button the Form widget execute primary UI Action, which is typically "Update" action. You can modify the code of Global UI Action "Update" to change the functionality of "Save" button.

ohh interesting...so we can just add to that UI Action code without cloning the Form widget right?  By doing it this way, any ongoing updates to that widget will still be applied correct?  Thanks!