- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 02:14 PM - edited 05-02-2024 02:16 PM
Hi everyone, Im trying to restrict possibility to create or modify tasks in change in state closed or cancelled, I tried to create some script or changing ui policie or create business rule but I didnt succeed so far, can you help me?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 03:39 PM
Hi @mamarusk ,
This requirement can be fulfilled in the below manner by creating a business rule.
Step 1:
Step 2:
(function executeRule(current, previous /*null when async*/) {
// Get the state of the parent change record
var change = new GlideRecord('change_request');
if (change.get(current.change_request)) { // Assumes 'change_request' is the field linking to the parent change
var state = change.state.toString();
// Define the states that are considered closed or cancelled, replace with actual state values in your instance
var closedStates = ['3', '4']; // Example: 3 = Closed, 4 = Cancelled.
if (closedStates.indexOf(state) !== -1) {
// If the change is in a closed or cancelled state, prevent modification or creation
gs.addErrorMessage('You cannot modify or add tasks to a change that is closed or cancelled.');
current.setAbortAction(true);
}
}
})(current, previous);
This will restrict any change task being created or updated from a closed/canceled change_request.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 08:53 PM
You can write before inser/update business rule, below is the sample script you can use it:
(function executeRule(current, previous /*null when async*/) {
// Check if the change request is in Closed or Cancelled state
if (current.state == 'closed' || current.state == 'cancelled') {
// Check if the operation is either insert or update
if (current.operation() == 'insert' || current.operation() == 'update') {
// Check if the user is trying to create or modify a task
if (current.type == 'task') {
// Cancel the current operation and display an error message
gs.addErrorMessage('Tasks cannot be created or modified when the change request is in Closed or Cancelled state.');
current.setAbortAction(true);
}
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 03:39 PM
Hi @mamarusk ,
This requirement can be fulfilled in the below manner by creating a business rule.
Step 1:
Step 2:
(function executeRule(current, previous /*null when async*/) {
// Get the state of the parent change record
var change = new GlideRecord('change_request');
if (change.get(current.change_request)) { // Assumes 'change_request' is the field linking to the parent change
var state = change.state.toString();
// Define the states that are considered closed or cancelled, replace with actual state values in your instance
var closedStates = ['3', '4']; // Example: 3 = Closed, 4 = Cancelled.
if (closedStates.indexOf(state) !== -1) {
// If the change is in a closed or cancelled state, prevent modification or creation
gs.addErrorMessage('You cannot modify or add tasks to a change that is closed or cancelled.');
current.setAbortAction(true);
}
}
})(current, previous);
This will restrict any change task being created or updated from a closed/canceled change_request.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 08:53 PM
You can write before inser/update business rule, below is the sample script you can use it:
(function executeRule(current, previous /*null when async*/) {
// Check if the change request is in Closed or Cancelled state
if (current.state == 'closed' || current.state == 'cancelled') {
// Check if the operation is either insert or update
if (current.operation() == 'insert' || current.operation() == 'update') {
// Check if the user is trying to create or modify a task
if (current.type == 'task') {
// Cancel the current operation and display an error message
gs.addErrorMessage('Tasks cannot be created or modified when the change request is in Closed or Cancelled state.');
current.setAbortAction(true);
}
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 12:04 AM
it works! thank you a lot, now I need to learn from your solution why my solutions arent work 😄 😉 thx