- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 07:23 AM
Good day everyone,
I have a use case for me to implement a check against CTASKS completion before the ticket can proceed to the next stage. The script provided below is being added to the Review UI Action on the change_request table and although the message does appear, it still proceeds to the Review state.
Could I get a review of the code below and assist on what I am missing? As I'm still new to scripting, looking for your insights.
Much appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 10:29 AM
@Joel O You can update the existing "Review" action condition as below,
gs.hasRole('itil,sn_change_write') && new ChangeFormUI(current).isReviewAvailable() && !(new ChangeRequest(current).hasOpenTasks())
By doing so, the "Review" button will be visible only after all the changes are closed/cancelled and make sure you the workflow modified accordingly so that it doesn't set the value of the state to "Review" automatically on closure of tasks.
Instead of "Set Values" you can modify it to "Wait for Review State as Condition" and have the "Review" UI action functionality without any changes.
Reference : https://www.servicenow.com/community/itsm-forum/donot-close-change-request-unless-all-change-tasks-a...
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 05:25 PM - edited 05-25-2024 05:26 PM
Hi @Joel O ,
The issue with the above script is that it sets the state to "Review" before checking for open tasks.
Please try with the below code-
function moveToReview() {
var gr = new GlideRecord("change_task");
gr.addQuery("change_request", g_form.getUniqueValue());
gr.addQuery("state", "<", "3"); // anything less than 3 is not closed
gr.setLimit(1);
gr.query();
if (gr.next()) {
g_form.addErrorMessage("Cannot move to Review state while Change Tasks are open.");
return false;
} else {
g_form.setValue("state", "0");
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_review");
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
The above script ensures that the state is only set to "Review" if there are no open change tasks, preventing the ticket from proceeding if tasks are still open.
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-25-2024 10:29 AM
@Joel O You can update the existing "Review" action condition as below,
gs.hasRole('itil,sn_change_write') && new ChangeFormUI(current).isReviewAvailable() && !(new ChangeRequest(current).hasOpenTasks())
By doing so, the "Review" button will be visible only after all the changes are closed/cancelled and make sure you the workflow modified accordingly so that it doesn't set the value of the state to "Review" automatically on closure of tasks.
Instead of "Set Values" you can modify it to "Wait for Review State as Condition" and have the "Review" UI action functionality without any changes.
Reference : https://www.servicenow.com/community/itsm-forum/donot-close-change-request-unless-all-change-tasks-a...
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 08:58 AM
Thank you for your response. This has been tested and working as intended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 05:25 PM - edited 05-25-2024 05:26 PM
Hi @Joel O ,
The issue with the above script is that it sets the state to "Review" before checking for open tasks.
Please try with the below code-
function moveToReview() {
var gr = new GlideRecord("change_task");
gr.addQuery("change_request", g_form.getUniqueValue());
gr.addQuery("state", "<", "3"); // anything less than 3 is not closed
gr.setLimit(1);
gr.query();
if (gr.next()) {
g_form.addErrorMessage("Cannot move to Review state while Change Tasks are open.");
return false;
} else {
g_form.setValue("state", "0");
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_review");
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
The above script ensures that the state is only set to "Review" if there are no open change tasks, preventing the ticket from proceeding if tasks are still open.
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-27-2024 08:58 AM
Thank you for your response. This too has been tested and working as intended.