spModal with text setting the value of a field (ServicePortal)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2024 06:34 AM
Hi everyone, Im trying to make a button "reject" on the portal to open a spModal to give a reason why they are rejecting the solution, I have been trying to use alert, but I have seen that the "spModal" is the best way to do it. I have never worked with it and Im not being able to find a good way to do this. can someone help please ?
Code:
HTML:
<li ng-if="data.ShowButtons">
<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("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';
var comment = prompt("Please enter a comment explaining the rejection:");
if (!comment) {
alert("Comment is mandatory to cancel the incident.");
return; // Exit the function if no comment is provided
}
Server Script:
var sys_id = $sp.getParameter('sys_id');
var tableName = $sp.getParameter('table');
var INCgr = new GlideRecord('incident');
var REQgr = new GlideRecord('sc_req_item');
REQgr.get(sys_id);
INCgr.get(sys_id);
data.ShowButtons = ((INCgr.state == '6' && INCgr.u_approved != 'true' && INCgr.u_rejected != 'true') || (REQgr.state == '3' && REQgr.u_approved != 'true' && REQgr.u_rejected != 'true'));
if (input.action == 'approve') {
if (tableName == 'sc_req_item') {
REQgr.u_approved = 'true'; // Closed Complete for sc_req_item
REQgr.update();
} else if (tableName == 'incident') {
INCgr.u_approved = 'true';
INCgr.state = '7'; // Closed for incident
INCgr.update();
}
} else if (input.action == 'reject') {
if (tableName == 'sc_req_item') {
REQgr.u_rejected = 'true'; // Work in Progress for sc_req_item
REQgr.update();
} else if (tableName == 'incident') {
INCgr.u_rejected = 'true';
INCgr.state = '2'; // In Progress for incident
INCgr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 07:35 AM
Hi @F_bio Santos ,
Kindly reorder the code as below:
var sys_id = $sp.getParameter('sys_id');
var tableName = $sp.getParameter('table');
if (input.action == 'approve') {
if (tableName == 'sc_req_item') {
REQgr.u_approved = 'true'; // Closed Complete for sc_req_item
REQgr.update();
} else if (tableName == 'incident') {
INCgr.u_approved = 'true';
INCgr.state = '7'; // Closed for incident
INCgr.update();
}
} else if (input.action == 'reject') {
if (tableName == 'sc_req_item') {
REQgr.u_rejected = 'true'; // Work in Progress for sc_req_item
REQgr.update();
} else if (tableName == 'incident') {
INCgr.u_rejected = 'true';
INCgr.state = '2'; // In Progress for incident
INCgr.update();
}
var INCgr = new GlideRecord('incident');
var REQgr = new GlideRecord('sc_req_item');
REQgr.get(sys_id);
INCgr.get(sys_id);
data.ShowButtons = ((INCgr.state == '6' && INCgr.u_approved != 'true' && INCgr.u_rejected != 'true') || (REQgr.state == '3' && REQgr.u_approved != 'true' && REQgr.u_rejected != 'true'));
}
Let me know if this works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 07:58 AM
Hi @debendudas it didnt I used some logs to check the values and it should be working.
I have tried to put "REG.gr.u_rejected == false" instead of using the " != true" but when I do that, the buttons dont show in any situation, Im not sure what Im doing wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 08:11 AM
Got it ... because the fields are boolean I shouldn't be using the '' for the "true" so instead of:
u_rejected != 'true';
it should be:
u_rejected != true;
without the ' '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 08:13 AM
Hi @F_bio Santos ,
Good to see you found the solution !! 👌