Comment Entry from Cancel Button not Copying

Erik Nelson
Mega Sage

Hello!

I've recently created a button to allow EUs to cancel their own request from the record view in Employee Center. I used the solution from this post to get the bulk of the work in place and everything works great, save for one thing. The comments entered in the box prior to submitting the cancellation do not copy over to their field on the record. Hoping someone can help point me to what I might be missing or have incorrect. The record is in a custom application that is extended from the Task table. Here's the code I have in place:

 

HTML:

<button type="button" class="btn btn-primary btn-block" ng-click="c.openModalCancel()" ng-if="data.showCancel">Cancel NTR</button>

<script type="text/ng-template" id="modalTemplateCancel">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Provide a reason for the cancel</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalTemplateResolve" ng-submit="c.uiAction('cancel')">
<div class="form-group">
<textarea required sp-autosize="true" ng-required="true" ng-model="data.cancelComments" id="cancelComments" placeholder="Comments required" class="form-control ng-pristine ng-valid ng-scope ng-empty ng-touched" aria-invalid="false" style="overflow: hidden; word-wrap: break-word; resize: horizontal;"></textarea>
</div>
<input class="btn btn-primary" type="submit" value="Submit Cancellation" />
</form>
</div>
</div>
</script>

 

Server Script:

 
(function() {

        // Get table & sys_id
        data.table = input.table || $sp.getParameter("table");
        data.sys_id = input.sys_id || $sp.getParameter("sys_id");
       
        // Valid GlideRecord
        gr = new GlideRecord(data.table);
        if (!gr.isValid())
            return;

        // Valid sys_id
        if (!gr.get(data.sys_id))
            return;

        //Button Visibility
        if (data.table == 'x_pgem_new_pge_t_0_new_tech_request' && gr.active == true && (gr.opened_by == gs.getUserID() || gs.hasRole("admin"))) {
            data.showWidget = true;

            data.showCancel = true;
        } else {
            data.showWidget = false;
            data.showCancel = false;
        }

        //input
        if (input && input.action) {
            var action = input.action;

            //New Tech Request Table
            if (data.table == 'x_pgem_new_pge_t_0_new_tech_request') {


                if (action == 'cancel') {
                    var workflow = new Workflow();
                    workflow.cancel(gr);
                    gr.setValue('stage', 10);
                    gr.setValue('state', 7);
                    gr.setValue('closed_by', gs.getUserID());
                    gr.setValue('close_notes', 'Cancelled by ' +gs.getUserDisplayName() + ' with comment: ' +input.cancelComments);
                        gr.update();
                    }

                }
            }
        })();
 
Client Script:
function($uibModal, $scope, spUtil) {
var c = this;

$scope.$on('record.updated', function(name, data) {
c.data.cancelComments = '';
spUtil.update($scope);
})

c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
c.modalInstance.close();
}

c.openModalCancel = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplateCancel',
scope: $scope
});
}


c.closeModal = function() {
c.modalInstance.close();
}
}

 

Thanks for any feedback/input!

 

Erik

1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @Erik Nelson 

 

1. confirm - the field type of close_notes in your custom table - is it String or Journal entry

 

2.  Can you try once 

From: 

         gr.setValue('close_notes', 'Cancelled by ' +gs.getUserDisplayName() + ' with comment: ' +input.cancelComments);

To:

gr.close_notes = 'Cancelled by ' +gs.getUserDisplayName() + ' with comment: ' +input.cancelComments ;

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti