In Service portal need to create 'Cancel' button after the request gets submitted

Arjun Reddy Yer
Tera Guru

Hi Friends,

 

I'm facing issue in creating "Cancel" button in Service Portal as it should look like in mentioned below screen shot. 

And when I tried to add widget as mentioned steps it's not getting added

  1. Go to the Ticket Page in SP, go look at an existing incident.

  2. Ctrl-Right click and select "Page in Designer"

  3. On the Widgets Sidebar drag-n-drop the "Cancel" widget on the form but it's not getting.

Can anyone help me @priyasunku @Ankur Bawiskar @BharathChintala @Sumalatha Y @AnveshKumar M @Allen Andreas @asifnoor @Brad Tilton @Pradeep Sharma @Sonu Parab @Sandeep Dutta @Hemant Goldar @Amit Gujarathi @Kieran Anson 

 

find_real_file.jpg

 

I tried with below Script but "Cancel" button is not visible as when the User Submit the Request then the "Cancel" button should be visible and after the "Request got Approved" then it should be disable.

 

HTML Script:

 

<div>
<div class="panel b" ng-if="data.showWidget">
<div class="panel-heading bg-primary">Actions</div>
<div class="panel-body">

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

</div>
</div>

<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" />
</form>
</div>
</div>
</script>

<script type="text/ng-template" id="modalTemplateStatus">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Provide any additional information</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalTemplateStatus" ng-submit="c.uiAction('status')">
<div class="form-group">
<textarea required sp-autosize="true" ng-required="true" ng-model="data.statusComments" id="statusComments" 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" />
</form>
</div>
</div>
</script>
</div>

 

Client Script:

api.controller=function() {
/* widget controller */
var c = this;
$scope.$on('record.updated', function(name, data) {
c.data.cancelComments = '';
c.data.statusComments = '';
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.openModalStatus = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplateStatus',
scope: $scope
});
}
c.closeModal = function() {
c.modalInstance.close();
};

 

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 == 'incident' && gr.active == true && gr.incident_state != 6 && (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))){
data.showWidget = true;
data.showCancel = true;
data.showStatus = true;

}
else if(data.table == 'incident' && gr.incident_state == 6 && (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))){
data.showWidget = true;
data.showCancel = false;
data.showStatus = false;

}
else if(data.table == 'sc_req_item' && gr.active == true && (gr.request.requested_for == gs.getUserID() || gs.hasRole("admin"))){
data.showWidget = true;
data.showCancel = true;
data.showStatus = true;

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

}

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

//Incident table
if (data.table == 'incident') {

if (action == 'cancel') {
gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('close_code','Customer Cancelled');
gr.setValue('close_notes','Cancelled by caller with comment: '+ input.cancelComments);
//gr.work_notes = 'Cancelled by caller with comment: ' + input.resolveComments;
gr.update();
}
}

//Requested Item table
if (data.table == 'sc_req_item' && input.cancelComments !='') {
if (action == 'cancel') {
var workflow = new Workflow();
workflow.cancel(gr);
gr.setValue('approval','withdrawn');
gr.setValue('stage','Request Cancelled');
gr.setValue('state','4');
gr.setValue('active','false');
gr.comments.setJournalEntry("Closed by Requested For with comment: "+ input.cancelComments);
gr.update();
}
if (action == 'status' && input.statusComments !='') {

gr.comments.setJournalEntry("Status request by user: "+ input.statusComments);
gr.update();
}
}

}
})();

 

1 ACCEPTED SOLUTION

Hi @Arjun Reddy Yer 

 

Try below code I did it in my PDI it worked.

 

HTML:

 

<div class="panel b" ng-if="data.showWidget">
<div class="panel-heading bg-primary">Actions</div>
<div class="panel-body">
<button type="button" class="btn btn-danger btn-block" ng-click="c.openModalCancel()" ng-if="data.showCancel">Cancel</button>
</div>
</div>


<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" />
</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 == 'incident' && gr.active == true && gr.incident_state != 6 && (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))){
data.showWidget = true;

data.showCancel = true;
}
else if(data.table == 'sc_req_item' && gr.active == true && (gr.request.requested_for == 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;

//Incident table
if (data.table == 'incident') {


if (action == 'cancel') {
gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('close_code','Customer Cancelled');
gr.setValue('close_notes','Cancelled by caller with comment: '+ input.cancelComments);
//gr.work_notes = 'Cancelled by caller with comment: ' + input.resolveComments;
gr.update();
}

}

//Requested Item table
if (data.table == 'sc_req_item' && input.cancelComments !='') {
if (action == 'cancel') {
var workflow = new Workflow();
workflow.cancel(gr);
gr.setValue('approval','withdrawn');
gr.setValue('stage','Request Cancelled');
gr.setValue('state','4');
gr.setValue('active','false');
gr.comments.setJournalEntry("Closed by Requested For with comment: "+ input.cancelComments);
gr.update();
}
if (action == 'status' && input.statusComments !='') {

gr.comments.setJournalEntry("Status request by user: "+ input.statusComments);
gr.update();
}
}

}
})();

 

client controller :

 

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();
}
}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

View solution in original post

9 REPLIES 9

Gone through the link but same issue

Hi @Arjun Reddy Yer 

 

Try below code I did it in my PDI it worked.

 

HTML:

 

<div class="panel b" ng-if="data.showWidget">
<div class="panel-heading bg-primary">Actions</div>
<div class="panel-body">
<button type="button" class="btn btn-danger btn-block" ng-click="c.openModalCancel()" ng-if="data.showCancel">Cancel</button>
</div>
</div>


<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" />
</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 == 'incident' && gr.active == true && gr.incident_state != 6 && (gr.caller_id == gs.getUserID() || gs.hasRole("admin"))){
data.showWidget = true;

data.showCancel = true;
}
else if(data.table == 'sc_req_item' && gr.active == true && (gr.request.requested_for == 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;

//Incident table
if (data.table == 'incident') {


if (action == 'cancel') {
gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('close_code','Customer Cancelled');
gr.setValue('close_notes','Cancelled by caller with comment: '+ input.cancelComments);
//gr.work_notes = 'Cancelled by caller with comment: ' + input.resolveComments;
gr.update();
}

}

//Requested Item table
if (data.table == 'sc_req_item' && input.cancelComments !='') {
if (action == 'cancel') {
var workflow = new Workflow();
workflow.cancel(gr);
gr.setValue('approval','withdrawn');
gr.setValue('stage','Request Cancelled');
gr.setValue('state','4');
gr.setValue('active','false');
gr.comments.setJournalEntry("Closed by Requested For with comment: "+ input.cancelComments);
gr.update();
}
if (action == 'status' && input.statusComments !='') {

gr.comments.setJournalEntry("Status request by user: "+ input.statusComments);
gr.update();
}
}

}
})();

 

client controller :

 

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();
}
}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

it should display once Request is Submitted like when User clicks on Submit button then "Cancel" button should display @priyasunku @Ankur Bawiskar @BharathChintala @Sumalatha Y @AnveshKumar M @Allen Andreas @asifnoor @Brad Tilton @Pradeep Sharma @Sonu Parab @Sandeep Dutta @Hemant Goldar @Amit Gujarathi @Kieran Anson @Anurag Tripathi @AJ-TechTrek @Chuck Tomasi 

 

And I'm unable to add the button as the process which I tried is not working so can you please suggest the process to add the button 

 

  1. Go to the Ticket Page in SP, go look at an existing incident.

  2. Ctrl-Right click and select "Page in Designer"

  3. On the Widgets Sidebar drag-n-drop the "Cancel" widget on the form but it's not getting.

As mentioned in below screen shot

yerasumalli_0-1679504060288.png

 

 

And in below script you had mentioned on incident table is it required to mention the script

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

//Incident table
if (data.table == 'incident') {


if (action == 'cancel') {
gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('close_code','Customer Cancelled');
gr.setValue('close_notes','Cancelled by caller with comment: '+ input.cancelComments);
//gr.work_notes = 'Cancelled by caller with comment: ' + input.resolveComments;
gr.update();
}

 

@Arjun Reddy Yer  it is working for me in my PDI. please copy the code which i have provided as it is.

 

priyasunku_0-1679644741323.png

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

As off now created HTML, Client Script written and below is the result for that 

 

yerasumalli_0-1679678190841.png

Client Script:

function ($scope, spUtil) {

spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);

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

but Server Script is unable to get me the result as when the User clicks on Cancel Button then the request should get canceled and should trigger a mail 

Can anyone help me @priyasunku @Ankur Bawiskar @BharathChintala @Sumalatha Y @AnveshKumar M @Allen Andreas @asifnoor @Brad Tilton @Pradeep Sharma @Sonu Parab @Sandeep Dutta @Hemant Goldar @Amit Gujarathi @Kieran Anson @Anurag Tripathi @Ajay Kumar011 @Chuck Tomasi 

 

Server Script:

(function(){
data.pickupMsg = gs.getMessage(options.pickup_msg);
var gr = $sp.getRecord();
if (gr == null)
return;

data.canRead = gr.canRead();
if (!data.canRead)
return;

var agent = "";
var a = $sp.getField(gr, 'assigned_to');
if (a != null)
agent = a.display_value;

var fields = $sp.getFields(gr, 'number,state,urgency,impact,priority,sys_created_on');
if (gr.getValue("sys_mod_count") > 0)
fields.push($sp.getField(gr, 'sys_updated_on'));

if (gr.getValue('price') > 0)
fields.push($sp.getField(gr, 'price'));

if (gr.getValue('recurring_price') > 0) {
var rp = $sp.getField(gr, 'recurring_price');
if (gr.isValidField("recurring_price"))
rp.display_value = rp.display_value + " " + gr.getDisplayValue("recurring_frequency");
fields.push(rp);
}
if (gr.isValidField("quantity"))
fields.push($sp.getField(gr, 'quantity'));

data.tableLabel = gr.getLabel();
data.fields = fields;
data.variables = new GlobalServiceCatalogUtil().getVariablesForTask(gr, true);
data.agent = agent;
data.agentPossible = gr.isValidField("assigned_to");
data.table = gr.getTableName();
data.sys_id = gr.getUniqueValue();
})()

//Cancel Button Performance is not executing with below script
if (data.table == 'sc_request') {
if (action == 'Cancel') {
// Cancel Request
gr.setValue('request_state','closed_cancelled');
// gr.setValue('request_state','closed_incomplete');
gs.addInfoMessage(gs.getMessage("You have cancelled Request : " +gr.number));
data.showRequest =false; // Making the Cancel Request button invisible
gr.update();
}