- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2017 10:57 PM
Friends,
I have an issue with service portal showing 'Cancel Incident' button for request , I am not good at coding.
Is it a coding issue, or can I fix this with minimum effort?
I have observed, It is showing correctly as cancel request if the ticket is in open/wip process until it gets approved.
Once approved the button showing is wrong.
I am giving the below W/F for actions button. Let me know if anything else required. Please advise me on this.
Client script
function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}
Server script
(function() {
data.showCancel = false; // Making cancel Incident button invisible
data.showReopen = false;
data.showRequest =false;
// 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;
// For reopen Button
if (gr.getValue('state') == '6') {
data.showReopen = true;
} else
data.showReopen = false;
// For Cancel Request Button
if (gr.getValue('request_state') == 'requested'){
data.showRequest =true;
} else
data.showRequest =false;
// For Cancel Incident Button
if (gr.getValue('state') == '1'&& gr.getValue('sla_due') != '') {
data.showCancel = true;
} else
data.showCancel = false;
if (input && input.action) {
var action = input.action;
// If Request table
if (data.table == 'sc_request') {
if (action == 'cancelrequest') {
// Cancel Request
//gr.setValue('incident_state', 8);
gr.setValue('request_state','closed_cancelled');
// gr.setValue('request_state','closed_incomplete');
gs.addInfoMessage(gs.getMessage("You have cancelled Request : " +gr.number));
//gr.setValue('resolved_by', gs.getUserID());
gr.comments = 'Request cancelled by ' + gs.getUserDisplayName() + ' via Service Portal';
gr.work_notes = 'Request Canceled by' + gs.getUserDisplayName() + ' via Service Portal';
data.showRequest =false; // Making the Cancel Request button invisible after the state is changed to 8
gr.update();
}
}
// If Incident table
if (data.table == 'incident') {
if (action == 'cancel') {
// Cancel Incident
//gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.u_cancellation_notes = 'Incident cancelled by ' + gs.getUserDisplayName() + 'via Service Portal';
gr.work_notes = 'Incident Canceled by' + gs.getUserDisplayName() + ' via Service Portal';
data.showCancel = false; // Making the Cancel button invisible after the state is changed to 8
gr.update();
}
if (action == 'Reopen') {
// Reopen the Incident
gr.setValue('incident_state',2);
gr.setValue('state',2);
gr.comments = 'Incident Reopned by' + gs.getUserDisplayName() + ' via Service Portal';
data.showReopen = false; // Making the reopen button invisible after the state is changed to 2
gr.update();
}
}
}
})();
Regards,
Srinivas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 06:29 AM
Corey,
We can see in the provided code that it is not a UI Action since the associated behaviour is coded in the Server Script :
// If Incident table
if (data.table == 'incident') {
if (action == 'cancel') {
// Cancel Incident
//gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.u_cancellation_notes = 'Incident cancelled by ' + gs.getUserDisplayName() + 'via Service Portal';
gr.work_notes = 'Incident Canceled by' + gs.getUserDisplayName() + ' via Service Portal';
data.showCancel = false; // Making the Cancel button invisible after the state is changed to 8
gr.update();
}
Moreover, there is no code to get the UI Actions in the Server side nor in the Client controller.
Regards,
Alexis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 07:22 AM
Srinivas,
You just have to be able to modify the widget. Did you try updating the Server Script with the conditions provided in my first reply (testing data.table) ?
If so and it doesn't work, please send me Server side code.
Regards,
Alexis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 07:31 AM
Alexis,
Thanks for quick response. I did the changes as per the changes you mentioned and logged out of SP.
Then I tested it failed.
Open the Widget to see the code , the changes done are gone. Here is the code
(function() {
data.showCancel = false; // Making cancel Incident button invisible
data.showReopen = false;
data.showRequest =false;
// 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;
// For reopen Button
if (gr.getValue('state') == '6') {
data.showReopen = true;
} else
data.showReopen = false;
// For Cancel Request Button
if (data.table == 'sc_request' && gr.getValue('request_state') == 'requested'){
data.showRequest =true;
} else
data.showRequest =false;
// For Cancel Incident Button
if (data.table == 'incident' && gr.getValue('state') == '1'&& gr.getValue('sla_due') != '') {
data.showCancel = true;
} else
data.showCancel = false;
if (input && input.action) {
var action = input.action;
// If Request table
if (data.table == 'sc_request') {
if (action == 'cancelrequest') {
// Cancel Request
//gr.setValue('incident_state', 8);
gr.setValue('request_state','closed_cancelled');
// gr.setValue('request_state','closed_incomplete');
gs.addInfoMessage(gs.getMessage("You have cancelled Request : " +gr.number));
//gr.setValue('resolved_by', gs.getUserID());
gr.comments = 'Request cancelled by ' + gs.getUserDisplayName() + ' via Service Portal';
gr.work_notes = 'Request Canceled by' + gs.getUserDisplayName() + ' via Service Portal';
data.showRequest =false; // Making the Cancel Request button invisible after the state is changed to 8
gr.update();
}
}
// If Incident table
if (data.table == 'incident') {
if (action == 'cancel') {
// Cancel Incident
//gr.setValue('incident_state', 8);
gr.setValue('state', 8);
gr.setValue('resolved_by', gs.getUserID());
gr.u_cancellation_notes = 'Incident cancelled by ' + gs.getUserDisplayName() + 'via Service Portal';
gr.work_notes = 'Incident Canceled by' + gs.getUserDisplayName() + ' via Service Portal';
data.showCancel = false; // Making the Cancel button invisible after the state is changed to 8
gr.update();
}
if (action == 'Reopen') {
// Reopen the Incident
gr.setValue('incident_state',2);
gr.setValue('state',2);
gr.comments = 'Incident Reopned by' + gs.getUserDisplayName() + ' via Service Portal';
data.showReopen = false; // Making the reopen button invisible after the state is changed to 2
gr.update();
}
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 07:49 AM
Hi Alexis,
Please ignore this mail, Now it is working, the save button did not work properly and changed did not save , now it is working
thanks a lot for your timely help
Regards,
Srinivas