want to make state field editable till one month after ticket is closed only for two users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 09:22 AM
"we want to make state field editable till one month after ticket is closed only for two users" in incident form, anyone please help how to achieve this
#client script #ACL #business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 11:30 AM - edited 07-25-2024 11:32 AM
Hi @siva14 ,
Yes, you're right. Creating a single Write ACL with a script to check the user's permissions and the conditions on the incident record can achieve the desired behavior effectively. Here's a detailed guide on how to implement this:
Steps to Create the Write ACL:
1. Create the Write ACL on the Incident Table
a. Navigate to **System Security > Access Control (ACL)** and click on **New**.
b. Configure the ACL as follows:
- **Type**: `record`
- **Operation**: `write`
- **Name**: `incident`
- **Condition**: [Leave empty or use a simple condition if needed]
2. Set the Condition:
- In the **Condition** builder, set a basic condition like `State is Closed` if you want to enforce this ACL only on closed incidents.
3. Advanced Script:
- Click on the **Advanced** checkbox to enable scripting.
- In the script section, add the following script:
// Define the sys_ids of the users who should have write access
var allowedUsers = ['user_sys_id_1', 'user_sys_id_2']; // Replace with actual sys_ids
// Function to check if the current user is allowed
function isUserAllowed() {
return allowedUsers.indexOf(gs.getUserID()) !== -1;
}
// Function to check if the incident is within one month of closure
function isWithinOneMonthOfClosure(current) {
var closedAt = current.closed_at;
if (!closedAt) {
return false;
}
var oneMonthLater = new GlideDateTime(closedAt);
oneMonthLater.addMonths(1);
var now = new GlideDateTime();
return now.compareTo(oneMonthLater) <= 0;
}
// Check both conditions
if (isUserAllowed() && isWithinOneMonthOfClosure(current)) {
answer = true;
} else {
answer = false;
}
Explanation:
1. **User Check:
- `allowedUsers` contains the sys_ids of the users who should have the write permission.
- `isUserAllowed()` checks if the current user's sys_id is in the list of allowed users.
2. Time Check:
- isWithinOneMonthOfClosure(current) checks if the current incident's `closed_at` date is within one month from now.
3. Condition Evaluation:
- The script returns `true` for `answer` if both conditions are met, making the incident editable for the specified users within one month of closure. Otherwise, it returns `false`, making the incident read-only.
Please mark this as helpful 😉
Thanks
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 04:26 AM - edited 07-26-2024 04:50 AM
Hi @Akshay Gupta2 , it's working, thanks for the help