Make Rejection comment mandatory in service portal

abirakundu23
Mega Sage

Hello All/ @Ankur Bawiskar  / @Mohith Devatte ,

We want to make mandatory field for Highlighted line as per attached screenshot.

We use the Following syntax .

    // For Our Rejection
         data.CONST = {
        i18n: {
            PLACEHOLDER_MESSAGE: gs.getMessage("If you are rejecting the request, provide the reason here."),
            REJECT_MODAL_TITLE: gs.getMessage("Reject Request"),
            REJECT_MODAL_MESSAGE: gs.getMessage("Please provide a reason for rejecting the request"),
            REJECT_MODAL_CANCEL: gs.getMessage("Cancel"),
            REJECT_MODAL_SUBMIT: gs.getMessage("Reject Request")
        },
        ACTION: "updateReject",
              REJECT_STATE: "rejected",
        APPROVED_STATE: "approved",
        REQUESTED_STATE: "requested",
        APPROVAL_TABLE: "sysapproval_approver"
             
    };

find_real_file.png

7 REPLIES 7

Also when you click on cancel on the window , buttons on the approval info form are grayed out until refresh.any solution 

Mohith Devatte
Tera Sage
Tera Sage

@absnow ,

YOU NEED TO MAKE THAT FIELD MANDATORY in modal window in HTML side 

share the modal window code once in HTML and i will be able to guide you

you need to put an attribute like 

required="required"

In the input field that you have built inside modal window

mark my answer correct if it helps you

Hi Mohith,

In html we added only button.

 <button aria-label="${Reject}" class="btn btn-default button-width" name="submit" value=${Submit} ng-click="$event.stopPropagation();onActionClick('rejected')">
        ${Reject}
      </button>

 

client part:

============

function hrESignSignDocumentController($scope, $rootScope, $window, nowServer, $http, $sce, $timeout, spModal, spUtil) {
    var c = this;
    
    // Accessibility for tab navigation
    $scope.$applyAsync(function() {
        new Tab("esign-tab-panel");
    });

    function Tab(id) {
        this._id = id;
        this.$tpanel = $('#' + id);
        this.$tabs = this.$tpanel.find('.tab');
        this.bindHandlers();
    }

    Tab.prototype.keys = {left: 37, right: 39};
    
    Tab.prototype.switchTabs = function($curTab, $newTab) {
        var $curLink = $curTab.find('a'),
        $newLink = $newTab.find('a');
        $curTab.removeClass('active');
        $curLink.attr('tabindex', '-1').attr('aria-selected', 'false');
        $newTab.addClass('active');
        $newLink.attr('aria-selected', 'true');
        $newLink.attr('tabindex', '0');
        $timeout(function(){
            $newLink.click();
            $newLink.focus();
        });
    }

    Tab.prototype.bindHandlers = function() {
        var self = this;
        this.$tabs.keydown(function(e) {
            return self.handleTabKeyDown($(this), e);
        });
    }

    Tab.prototype.moveToPreviousOrNext = function(e, $tab, next) {
        var $newTab, tabIndex;
        tabIndex = this.$tabs.index($tab);
        var index = (next) ? this.$tabs.length - 1 : 0;
        if (tabIndex === index) {
            $newTab = (next) ? this.$tabs.first() : this.$tabs.last();
        } else {
            var newIndex = (next) ? tabIndex + 1 : tabIndex - 1;
            $newTab = this.$tabs.eq(newIndex);
        }
        this.switchTabs($tab, $newTab);
        e.preventDefault();
        return false;
    }

    Tab.prototype.handleTabKeyDown = function($tab, e) {
        if (e.keyCode == this.keys.left) {
            this.moveToPreviousOrNext(e, $tab);
        } else if (e.keyCode == this.keys.right) {
            this.moveToPreviousOrNext(e, $tab, true);
        }
    }

    var MOBILE_DEVICE_SCREEN_WIDTH = 767;
    $scope.mobileDevice = c.data.isMobile || ($window.innerWidth < MOBILE_DEVICE_SCREEN_WIDTH);
    c.showDoc = false;
    c.signed_name = "";
    $scope.showUpdating = false;
    c.showSigPad = false;
    $scope.acknowledgeType = '';
    $scope.document_revision = '';
    $scope.documentBody = $sce.trustAsHtml($scope.data.documentBody);
    $scope.isTypeTab = true;
    $scope.signType =$scope.data.esign_type;
    $scope.checked = $scope.data.task.acknowledgement_text ? false : true;
    $scope.isSignPadVisible = false;
    $scope.isLargeAcknowledgement =($scope.data.task.acknowledgement_text && ($scope.data.task.acknowledgement_text.length> 100)) ? true: false;
    $scope.moreInfoCollapsed = true;

    c.clearInput = function() {
        c.clearCanvas();
        c.signed_name = "";
        document.getElementById('signed_name').value="";
        $scope.toggleAcceptButton();
    };

    c.clearCanvas = function() {
        if(c.sigPad)
            c.sigPad.clearCanvas();
        $scope.toggleAcceptButton();
    };

    c.openTab = function(tab) {
        $scope.isTypeTab = false;
        $scope.isDrawTab = false;
        c.clearInput();
        if(tab == "draw") {
            $scope.isDrawTab = true;
            c.resetSignaturePad();
        }
        else
            $scope.isTypeTab = true;
        $scope.toggleAcceptButton();
    };

    c.sigPad = null;

    $scope.getTasks = function(sys_id) {
        $scope.data.action = "getTasks";
        $scope.data.sys_id = sys_id;
        $scope.server.update();
    };

    c.doSaveSignature = function(actionName, table, document, image, data, acknowledgmentText) {

        var n = {
            action : actionName,
            table : table,
            document : document,
            sp : true,
            time : new Date().getTime(),
            acknowledgement_text : encodeURIComponent(acknowledgmentText)
        };

        var da = {
            image : image,
            data : data
        };

        var dataURL = '';
        Object.keys(n).forEach(function(t) {
            dataURL += "&" + t + "=" + n[t];
        });

        return $http.post(nowServer.getURL('SignatureANGProcessor', dataURL), da);
    };

    $scope.isAcknowledged = function() {
        $scope.checked = !$scope.checked;
        $scope.toggleAcceptButton();
    };

    $scope.toggleAcceptButton = function(){
        var isSignatureDone = ( document.getElementById('signed_name').value!="" || 
              (document.getElementById('drawPad_image').value!="" && document.getElementById('drawPad_image').value!="[]"));
        if($scope.checked && isSignatureDone)
            document.getElementById('agree-button_'+$scope.data.sys_id).disabled=false;
        else
            document.getElementById('agree-button_'+$scope.data.sys_id).disabled=true;
    }

    $scope.enableAcceptButton = function(){
        if($scope.checked)
            document.getElementById('agree-button_'+$scope.data.sys_id).disabled=false;
    };

    $scope.toggleAcceptButtonSignPad = function(){
        setTimeout($scope.toggleAcceptButton, 100);
    }

    $scope.showSignPad = function(){
        $rootScope.$broadcast('mobile-showSignPad');
        document.getElementById('drawPad_'+$scope.data.sys_id).width=parseInt($window.innerWidth)-80;
    }

    $scope.$on('mobile-showSignPad', function(event, args) {
        $scope.isSignPadVisible = !$scope.isSignPadVisible;
    })

    $scope.strLimit = 250;
    $scope.toggleMoreInfo = function() {
        $scope.strLimit = $scope.moreInfoCollapsed ? $scope.data.task.acknowledgement_text.length : 250;
        $scope.moreInfoCollapsed = !$scope.moreInfoCollapsed;
    };


    $scope.setTaskFinished = function(sys_id, user_id, signature) {
        $scope.showUpdating = true;
        $scope.data.action = 'setTaskFinished';
        $scope.data.request = {
            sys_id : sys_id,
            user_id : user_id,
            signature : signature
        };

        $scope.server.update().then(function(data) {
            c.isPopoverOpen = false;
            $scope.showUpdating = false;
        });
    };
    
    c.sendCompletionBroadcast = function(){
        $rootScope.$broadcast("sn_hr_sp.esignComplete");
    };
    
    // For Our Rejection
    
    
     $scope.onActionClick = function(state) {
                console.log("Data1=");
            if (true) {
            if (true) {
                // Create an input popup
                spModal.open({
                    title: c.data.CONST.i18n.REJECT_MODAL_TITLE,
                    message: c.data.CONST.i18n.REJECT_MODAL_MESSAGE,
                    input: true,
                    buttons: [
                        {label: c.data.CONST.i18n.REJECT_MODAL_CANCEL, cancel: true},
                        {label: c.data.CONST.i18n.REJECT_MODAL_SUBMIT, primary: true}
                    ]
                }).then(function(comment) {
                    sendUpdateRequest(state, true, c.data.CONST.ACTION, comment);
                });
            } else
                sendUpdateRequest(state, true, c.data.CONST.ACTION, c.data.comments);
        } else if (state === c.data.CONST.APPROVED_STATE)
            sendUpdateRequest(state, false, c.data.CONST.ACTION, c.data.comments);
        return false; //prevents the form from submitting when the dialog first loads
    };
    function sendUpdateRequest(state, reject, action, comment){
        $scope.data.action = action;
                c.data.comments=comment;
        $scope.server.update();
    }
    }

server part:

==========

// For Our Rejection
         data.CONST = {
        i18n: {
            PLACEHOLDER_MESSAGE: gs.getMessage("If you are rejecting the request, provide the reason here."),
            REJECT_MODAL_TITLE: gs.getMessage("Reject Request"),
            REJECT_MODAL_MESSAGE: gs.getMessage("Please provide a reason for rejecting the request"),
            REJECT_MODAL_CANCEL: gs.getMessage("Cancel"),
            REJECT_MODAL_SUBMIT: gs.getMessage("Reject Request")
        },
        ACTION: "updateReject",
              REJECT_STATE: "rejected",
        APPROVED_STATE: "approved",
        REQUESTED_STATE: "requested",
        APPROVAL_TABLE: "sysapproval_approver"
             
    };

    var approvalGr = null;
    var commentGr = null;
    
   if (input && input.action === data.CONST.ACTION) {
                 var    gr = new GlideRecord("sn_hr_core_task");
                 gr.addQuery('sys_id',data.sys_id);
                 gr.query();
                 if(gr.next())
                    {
                        gr.comments = input.comments;
                        gr.state= 7;
                        gr.update();
                    }

     }
     })();