ServiceNow Widget to Approve/Reject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2024 08:19 AM
Hi everyone, Im trying to add two buttons on a portal widget. One that will approve the record and make the state "Closed Complete" and other that will reject and make the state "work in progress" it may be for the "incident" table or for the "sc_req_item". Im not being able to make it work, when I click on the buttons nothing happens. I believe that is something on the "Client Script" but Im not sure ... can someone help with this ?
Code:
HTML:
<li>
<a href="javascript:void(0)" ng-click="approve()">Approve</a>
<a href="javascript:void(0)" ng-click="reject()">Reject</a>
</li>
Client Script:
$scope.approve = function() {
console.log($scope.data.approve);
$scope.server.update();
c.server.update().then(function(){
$scope.data.action = 'approve';
//$scope.update();
})
}
$scope.reject = function() {
console.log($scope.data.reject);
$scope.server.update();
c.server.update().then(function(){
$scope.data.action = 'reject';
//$scope.update();
})
}
Server Script:
data.sys_id = $sp.getParameter('sys_id');
data.tableName = $sp.getParameter('table');
if (input && input.action){
var action = input.action;
if (action == 'approve' || data.tableName == 'sc_req_item'){
REQgr.setValue('state', '3');
REQgr.update();
} else if(action == 'reject' || data.tableName == 'sc_req_item'){
REQgr.setValue('state', '2');
REQgr.update();
} else if(action == 'approve' || data.tableName == 'incident'){
INCgr.setValue('state', '6');
INCgr.update();
} else if(action == 'reject' || data.tableName == 'incident'){
INCgr.setValue('state', '2');
INCgr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2024 08:38 AM
Hi @F_bio Santos Try below Scripts
Client Script :
$scope.approve = function() {
console.log("Approving record with sys_id: " + $scope.data.sys_id);
$scope.data.action = 'approve';
$scope.server.update();
};
$scope.reject = function() {
console.log("Rejecting record with sys_id: " + $scope.data.sys_id);
$scope.data.action = 'reject';
$scope.server.update();
};
Server Script :
(function() {
var sys_id = $sp.getParameter('sys_id');
var tableName = $sp.getParameter('table');
var gr;
if (tableName === 'sc_req_item') {
gr = new GlideRecord('sc_req_item');
} else if (tableName === 'incident') {
gr = new GlideRecord('incident');
}
if (gr) {
if (gr.get(sys_id)) {
if (input.action === 'approve') {
if (tableName === 'sc_req_item') {
gr.setValue('state', '3'); // Closed Complete for sc_req_item
} else if (tableName === 'incident') {
gr.setValue('state', '6'); // Closed Complete for incident
}
} else if (input.action === 'reject') {
if (tableName === 'sc_req_item') {
gr.setValue('state', '2'); // Work in Progress for sc_req_item
} else if (tableName === 'incident') {
gr.setValue('state', '2'); // Work in Progress for incident
}
}
gr.update();
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2024 10:00 AM - edited ‎09-03-2024 10:01 AM
Hi @Sid_Takali I changed it, but it didnt work, anyway it helped me understand what I was doing wrong ... and now its working