Add button to simple list widget
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2020 11:26 PM
How to add a custom button to list widget. This button should be able to update one field in the table.
Labels:
- Labels:
-
Service Portal
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2020 01:35 AM
Hi,
Do some script changes in this code according to your conditions :
HTML :
<div class="panel panel-default">
<div class="panel-heading">Actions</div>
<div class="panel-body">
<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('resolve')">Resolve Incident</button>
<button type="button" class="btn btn-default btn-block" ng-click="c.uiAction('cancel')">Cancel</button>
</div>
</div>
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() {
// 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;
if (input && input.action) {
var action = input.action;
// If Incident table
if (data.table == 'incident') {
if (action == 'resolve') {
// Resolve Incident
gr.setValue('incident_state', 6);
gr.setValue('state', 6);
gr.setValue('resolved_by', gs.getUserID());
gr.update();
}
if (action == 'cancel') {
// Do something else
}
}
}
})();
for your reference :
I hope it will help you.
If you find my answer is helpful or correct to you. Please mark it accordingly.
Thanks..!