Based on your requirements and the provided code snippets, there are a few places where adjustments and additions are necessary to enable the "Reopen Request" button along with managing its visibility based on the request item's state and its closed date. The tricky part lies in showing the "Reopen Request" button only when the Request Item (sc_req_item) is in the closed_complete state and for only 5 days after closing.
Adjustments and Additions
-
Server Script Modifications:
Firstly, you should add logic to handle the ReopenRequestItem action as well as logic to determine whether the "Reopen Request" button should be shown. This involves:
- Checking if the
closed_complete state for the item (state equals to the value representing closed_complete) and calculating the difference between the current date and the date at which the item was moved to closed_complete.
- Implementing the action to handle reopening the request item.
-
HTML Changes:
To ensure that all action buttons are organized under a dropdown menu, you might need to adjust your HTML structure. The provided code snippet shows buttons side by side because they are not wrapped inside a dropdown structure.
-
Code Enhancements:
- Server Side: Add logic to support showing the reopen button under specific conditions.
- Client Side: No changes indicated as necessary; your client controller seems adequate for calling actions based on button clicks.
Server-Side Script Enhancement Example
Let's add the logic for showing the reopen button only if the state is closed_complete and if less than 5 days have passed since the closure. The closed_complete state might differ in your instance, so replace '100' with the correct state value, and update date field references as necessary.
- Determining visibility for the Reopen Button:
// At the start where variables are initialized
data.showReopenButton = false; // Initial state of the button visibility
var now = new GlideDateTime();
var closedDate = new GlideDateTime(gr.u_closed_date); // Assuming 'u_closed_date' is the custom closed date field. Adjust this field name as per your instance's configuration.
var timeDifference = GlideDateTime.subtract(now, closedDate); // Get the difference
var daysSinceClosed = timeDifference.getNumericValue() / (1000 * 60 * 60 * 24); // Convert difference to days
// Conditions to show the Reopen button
if (ritm_state == '100' /* assuming '100' is the state value for closed_complete */ && daysSinceClosed <= 5) {
data.showReopenButton = true;
}
- Implementing the action to reopen the request item:
if (action =='ReopenRequestItem'){
gr.setValue('state', 1); // Set to Open or the state you wish to revert it to
gr.update();
// Optionally add a comment or log message
}
HTML Changes for Action Dropdown
Here is a basic example of restructuring your HTML to include a dropdown menu. This simplifies grouping all actions under a single dropdown.
<!-- Dropdown Button -->
<div class="dropdown" ng-if="data.showRITMCancelButton || data.showReopenButton">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">${Action}
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li ng-if="data.showRITMCancelButton"><a href="#" ng-click="c.uiAction('cancelRequestItem')">${Cancel Request}</a></li>
<li ng-if="data.showReopenButton"><a href="#" ng-click="c.uiAction('ReopenRequestItem')">${Reopen Request}</a></li>
</ul>
</div>
Conclusion
Remember to replace placeholders like '100' with the actual state value for closed_complete in your instance and u_closed_date with the actual field name used to track the request item's closure date. The interaction between your AngularJS client controller and the server script seems adequately structured for invoking the corresponding actions. This should guide you towards implementing the desired functionality.