|
| 1 | +# Setup Instructions for Cancel Incident UI Action |
| 2 | + |
| 3 | +This document provides detailed step-by-step instructions for implementing the Cancel Incident UI Action in your ServiceNow instance. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Administrative access to ServiceNow instance |
| 8 | +- Access to System Definition > UI Actions module |
| 9 | +- Understanding of ServiceNow UI Actions and client-server scripting |
| 10 | + |
| 11 | +## Step-by-Step Setup |
| 12 | + |
| 13 | +### 1. Navigate to UI Actions |
| 14 | + |
| 15 | +1. In ServiceNow, go to **System Definition > UI Actions** |
| 16 | +2. Click **New** to create a new UI Action |
| 17 | + |
| 18 | +### 2. Configure Basic Settings |
| 19 | + |
| 20 | +Fill in the following fields: |
| 21 | + |
| 22 | +| Field | Value | Description | |
| 23 | +|-------|-------|-------------| |
| 24 | +| **Name** | Cancel Incident | Display name for the UI Action | |
| 25 | +| **Table** | Incident [incident] | Target table for the UI Action | |
| 26 | +| **Action name** | cancel_incident | Unique identifier for the action | |
| 27 | +| **Active** | ✓ (checked) | Enables the UI Action | |
| 28 | + |
| 29 | +### 3. Configure Display Settings |
| 30 | + |
| 31 | +| Field | Value | Description | |
| 32 | +|-------|-------|-------------| |
| 33 | +| **Form button** | ✓ (checked) | Shows button on form view | |
| 34 | +| **Form link** | ☐ (unchecked) | Optional: Show as link instead | |
| 35 | +| **List banner button** | ☐ (unchecked) | Not needed for this action | |
| 36 | +| **List choice** | ☐ (unchecked) | Not needed for this action | |
| 37 | + |
| 38 | +### 4. Configure Client Settings |
| 39 | + |
| 40 | +| Field | Value | Description | |
| 41 | +|-------|-------|-------------| |
| 42 | +| **Client** | ✓ (checked) | Enables client-side execution | |
| 43 | +| **Onclick** | `cancelIncident();` | Client-side function to call | |
| 44 | + |
| 45 | +### 5. Configure Conditions |
| 46 | + |
| 47 | +| Field | Value | Description | |
| 48 | +|-------|-------|-------------| |
| 49 | +| **Condition** | `current.state == '1'` | Only show for "New" incidents | |
| 50 | + |
| 51 | +### 6. Add the Script |
| 52 | + |
| 53 | +Copy the entire content from `script.js` and paste it into the **Script** field of the UI Action. |
| 54 | + |
| 55 | +### 7. Configure Advanced Settings (Optional) |
| 56 | + |
| 57 | +| Field | Value | Description | |
| 58 | +|-------|-------|-------------| |
| 59 | +| **Order** | 100 | Display order (adjust as needed) | |
| 60 | +| **Hint** | Cancel this incident | Tooltip text | |
| 61 | +| **Comments** | UI Action to cancel incidents in New state | Internal documentation | |
| 62 | + |
| 63 | +## Verification Steps |
| 64 | + |
| 65 | +### 1. Test the UI Action |
| 66 | + |
| 67 | +1. Navigate to an incident in "New" state |
| 68 | +2. Verify the "Cancel Incident" button appears |
| 69 | +3. Click the button and confirm the modal appears |
| 70 | +4. Test both "OK" and "Cancel" in the confirmation dialog |
| 71 | + |
| 72 | +### 2. Verify State Changes |
| 73 | + |
| 74 | +1. After confirming cancellation, check that: |
| 75 | + - Incident state changes to "Cancelled" |
| 76 | + - Work notes are added with cancellation details |
| 77 | + - Success message appears |
| 78 | + |
| 79 | +### 3. Test Edge Cases |
| 80 | + |
| 81 | +1. Try accessing the UI Action on incidents in other states (should not appear) |
| 82 | +2. Test with different user roles to ensure proper permissions |
| 83 | +3. Verify error handling works correctly |
| 84 | + |
| 85 | +## Troubleshooting |
| 86 | + |
| 87 | +### Common Issues |
| 88 | + |
| 89 | +**UI Action doesn't appear:** |
| 90 | +- Check that the incident is in "New" state (state = 1) |
| 91 | +- Verify the condition field: `current.state == '1'` |
| 92 | +- Ensure the UI Action is marked as Active |
| 93 | + |
| 94 | +**Script errors:** |
| 95 | +- Check browser console for JavaScript errors |
| 96 | +- Verify the script is properly copied from `script.js` |
| 97 | +- Ensure proper syntax and formatting |
| 98 | + |
| 99 | +**Permission issues:** |
| 100 | +- Verify user has write access to incident table |
| 101 | +- Check ACL rules for incident cancellation |
| 102 | +- Ensure proper role assignments |
| 103 | + |
| 104 | +### Debug Mode |
| 105 | + |
| 106 | +To enable debug logging, add this line at the beginning of the `serverCancel()` function: |
| 107 | + |
| 108 | +```javascript |
| 109 | +gs.info('Debug: Starting incident cancellation for ' + current.number); |
| 110 | +``` |
| 111 | + |
| 112 | +## Security Considerations |
| 113 | + |
| 114 | +- The UI Action respects existing ACL rules |
| 115 | +- Only users with incident write permissions can cancel incidents |
| 116 | +- All cancellations are logged for audit purposes |
| 117 | +- Work notes provide cancellation history |
| 118 | + |
| 119 | +## Customization Options |
| 120 | + |
| 121 | +### Modify Confirmation Message |
| 122 | + |
| 123 | +Edit line 33 in the script to customize the confirmation dialog: |
| 124 | + |
| 125 | +```javascript |
| 126 | +gm.setPreference("question", "Your custom message here"); |
| 127 | +``` |
| 128 | + |
| 129 | +### Change Cancellation Reason |
| 130 | + |
| 131 | +Modify the work note in the `serverCancel()` function (line 79): |
| 132 | + |
| 133 | +```javascript |
| 134 | +var workNote = 'Custom cancellation reason: ' + gs.getUserDisplayName() + ' on ' + gs.nowDateTime(); |
| 135 | +``` |
| 136 | + |
| 137 | +### Add Additional Validations |
| 138 | + |
| 139 | +Add custom validation logic in the `cancelIncident()` function before showing the modal. |
| 140 | + |
| 141 | +## Support |
| 142 | + |
| 143 | +For issues or questions: |
| 144 | +1. Check ServiceNow system logs |
| 145 | +2. Review browser console for client-side errors |
| 146 | +3. Test in a development instance first |
| 147 | +4. Consult ServiceNow documentation for UI Actions |
0 commit comments