Widget button in service portal my request page

SAM321
Tera Contributor

Hi all so I have a task , creation of widget button on (my request page) of service portal.

The buttons are (Accept resolution) and (Reject resolution).

This buttons should be display only when incident state is resolved.

 

When clicking on “Accept Resolution” button, the incident state must be updated to Closed with an additional comments written : “Resolution accepted by the user”.

 

When clicking on Reject Resolution, a popup should be displayed with “Additional Comments” to be populated by the user. Then the incident state must be updated to “Work In Progress” and assignment group must be notified.

 

I created buttons using HTML and CSS but I have problem with client and server side script. can someone help!

 

18 REPLIES 18

Create a widget global scope)  with below code and place it on "ticket" page (service portal standard ticket scope):

 

HTML:
<div ng-if="data.show">
  <button id="accept" ng-click="c.accept()">Accept</button>
  <button id="reject" ng-click="c.reject()">Reject</button>
</div>

Server:
(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */


    var inc = new GlideRecord('incident');
    inc.addQuery('sys_id', $sp.getParameter('sys_id'));
    inc.query();
    if (inc.next()) {
        if ($sp.getParameter('table') == 'incident' && inc.state == 6) {
            data.show = true;
        }

        if (input.action == 'accept') {
            inc.state = 7; // setting state to close
            inc.comments = "test"; // add your comments
            inc.update();
        }
		else if(input.action=='reject')
			{
				inc.state=2; // in progress state
				inc.comments= input.add_comments;
				inc.update();
			}

    }

})();
Client:

api.controller = function(spModal) {
    /* widget controller */
    var c = this;


    c.accept = function() {
        c.data.action = 'accept';
        c.server.update();
    };

    c.reject = function() {
       spModal.open({
            title: 'Additional Comments',
            message: 'Additional Comments',
            input: true,
            value: c.name
        }).then(function(name) {
            c.data.add_comments =name;
		   c.data.action = 'reject';
            c.server.update();
        });
        
    };
	

	
};

 The button will be visible for resolved incidents.


Please mark the answer correct/helpful accordingly. 


Raghav
MVP 2023

@SAM321 did this work for you?


Raghav
MVP 2023

SAM321
Tera Contributor

@RaghavSh the task is paused ..once i restart it i let u know sir

SAM321
Tera Contributor

@RaghavSh yes button should visible on resolved incidents

i attached HTML, Client and server script

SAM321
Tera Contributor

@RaghavSh I have doubt in (maintenance plan) task...I don't know how it works..can u give some ideas on it.