Service Portal:OOB Approval widget

gomathyshankar
Tera Contributor

Hi,

How to add the comments field in the OOB Approval widget and make it mandatory when the approvers rejects it.

1 ACCEPTED SOLUTION

Hi Selva,



Use the below and it wil work ( we have to change both client and server to update user comments in approval table)



Highlighted are the changes



Client controller:


function ($scope, spUtil, snRecordWatcher,spModal) {



  if ($scope.options.portal == true || $scope.options.portal == 'true') {


      $scope.contentColClass = "col-xs-12";


  $scope.options.portal = true;


  } else {


  $scope.options.portal = false;


  $scope.contentColClass = "col-sm-9";


  }




  $scope.data.op = "";


  snRecordWatcher.initList("sysapproval_approver", "state=requested^approver=" + window.NOW.user_id);




  function get() {


      spUtil.update($scope);


  }




  $scope.$on('record.updated', function(name, data) {


  get();


  })




  $scope.approve = function(id) {


      $scope.data.op = "approved";


      $scope.data.target = id;


      get();


  }




  $scope.reject = function(id) {


    c.onPrompt(id);


  }


c.onPrompt = function(id) {  


                spModal.open({  


                      title: 'Give me a comment',  


                      message: 'Your comment please?',  


                      input: true,  


                      value: c.comment  


              }).then(function(comment) {  


                      c.comment = comment;  


  if(comment)


  {


                      $scope.data.comment = comment;  


  $scope.data.op = "rejected";


  $scope.data.target = id;


  get();


  }


              })  


      }


}



Server side:


Replace


if (input && input.op) {


  var app = new GlideRecord("sysapproval_approver");


  if (app.get(input.target)) {


      app.state = input.op;


      app.update();


  }



With



if (input && input.op) {



  if(input.op == 'approved')


  {


  var app = new GlideRecord("sysapproval_approver");


  if (app.get(input.target)) {


      app.state = input.op;


      app.update();


  }


  }


  else if(input.op == 'rejected' && input.comment)


  {


  var app = new GlideRecord("sysapproval_approver");


  if (app.get(input.target)) {


    app.comments = input.comment;


      app.state = input.op;


      app.update();


  }


  }




Thanks and regards


Swamy


View solution in original post

38 REPLIES 38

Hi Harel,

 

Yes, i can able to fix the issue with that solution. Thank you.

adrianherdan
Kilo Expert

In the Client script, replace   sp.update with c.server.gets



Below the full client script that fixes the comment issue:


function ($scope, spUtil, snRecordWatcher,$window,$location,spModal,$uibModal) {


                              var c = this;


                              if ($scope.options.portal == true || $scope.options.portal == 'true') {


                                                              $scope.contentColClass = "col-xs-12";


                                                              $scope.options.portal = true;


                              } else {


                                                              $scope.options.portal = false;


                                                              $scope.contentColClass = "col-sm-9";


                              }


                              $scope.data.op = "";


                              snRecordWatcher.initList("sysapproval_approver", "state=requested^approver=" + window.NOW.user_id);


                              spUtil.recordWatch($scope, c.options.table, c.options.filter);



                              function get() {


                                                              spUtil.update($scope);


                              }



                              $scope.$on('record.updated', function(name, data) {


                                                              get();


                              })



                              // APROVE


                              $scope.approve = function(id) {


                                                              $scope.data.op = "approved";


                                                              $scope.data.target = id;


                                                              get();


                                                              spUtil.addInfoMessage('You have approved this request!');


                              }



                              // REJECT


                              $scope.reject = function(id) {


                                                              c.onPromptr(id);


                              }


                              c.onPromptr = function(id) {


                                                              spModal.open({


                                                                                              title: 'Rejection Comment',


                                                                                              message: 'Please state a reason for rejection',


                                                                                              input: true,


                                                                                              value: c.comment


                                                              }).then(function(comment) {


                                                                                              c.comment = comment;


                                                                                              if(comment) {


                                                                                                                              c.server.get ({


                                                                                                                                                              comment: comment,


                                                                                                                                                              op: "rejected",


                                                                                                                                                              target: id


                                                                                                                              }).then(function(r) {                                                                            


                                                                                                                                                              c.comment='';


                                                                                                                              });


                                                                                              }


                                                                                              spUtil.addErrorMessage('You have rejected this request!')


                                                              })


                              }



}


adrianherdan ,



You are most awesomely awesome.


I opened a HI incident about the multiple updates and they could not find the cause for it.


Thanks for taking the time to update and post.



harel


jituksingh
Kilo Guru

Hi All,



I utilized above script in a clone of approval widget but when I added the clone the widget is not visible on SP page. I am not even able remove it. Can you please what could be the issue.



Regards,


Jitendra Singh