- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 12:50 AM
Hi can you help me on this scenario wherein my Change Request when the state is on Scheduled my Script Include and UI Action should validate and cant proceed if my task is on Open, Pending, Closed State. Then when my state is on Review and i want to close the ticket upon clicking on the Close Button there should be a validation to check if my task Review is still Open or Close. If Open there should be a ErrorMessage and cant proceed to close then if its Closed it will proceed.
here is my code in Script Include where it supposed to be my checker for a Review Task if open but i always got false answer even though its correct.
here is my UI Action were i get the value from my Script Include
here is what i got false answer wherein its supposed to be true because my task Review type state is Open
here is my another ticket wherein my Review Task State is closed which is correct way i supposed to be expecting.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:17 AM
Hi,
update as this
hasActiveReview: function() {
var ccrid = this.getParameter('sysparm_crid');
var cctask = new GlideRecord('change_task');
cctask.addActiveQuery();
cctask.addQuery('change_request', ccrid);
cctask.addQuery('change_task_type', 'review'); //check P.I.R. Task
cctask.query();
return cctask.hasNext();
},
UI Action
var hasActiveReviewAjax = new GlideAjax('ChangeRequestStateHandlerAjax');
hasActiveReviewAjax.addParam('sysparm_name', 'hasActiveReview');
hasActiveReviewAjax.addParam('sysparm_crid', g_form.getUniqueValue());
hasActiveReviewAjax.getXMLAnswer(function(answer){
if(answer.toString() == 'true'){
g_form.addErrorMessage('A Review task is still open');
}
else{
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");
}
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:38 AM
Hi
hasActiveReview: function() {
var ccrid = this.getParameter('sysparm_crid');
var cctask = new GlideRecord('change_task');
cctask.addActiveQuery();
cctask.addQuery('change_request', ccrid);
cctask.addQuery('change_task_type', 'review'); //check P.I.R. Task
cctask.query();
return cctask.hasNext();
},
var hasActiveReviewAjax = new GlideAjax('ChangeRequestStateHandlerAjax');
hasActiveReviewAjax.addParam('sysparm_name', 'hasActiveReview');
hasActiveReviewAjax.addParam('sysparm_crid', g_form.getUniqueValue());
hasActiveReviewAjax.getXMLAnswer(function(answer){
if(answer.toString() == 'true'){
g_form.addErrorMessage('A Review task is still open');
}
else{
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");
}
});
upon trying this scenario is theres a way were in when i click on close it doesnt submit like stays in the form? because when i click on the close button it loads like i submitted it. also is theres a way like script that i check on states value if open, pending, or in progress?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 01:41 AM
Hi,
if you use return statement then it will stay on the form
var hasActiveReviewAjax = new GlideAjax('ChangeRequestStateHandlerAjax');
hasActiveReviewAjax.addParam('sysparm_name', 'hasActiveReview');
hasActiveReviewAjax.addParam('sysparm_crid', g_form.getUniqueValue());
hasActiveReviewAjax.getXMLAnswer(function(answer){
if(answer.toString() == 'true'){
g_form.addErrorMessage('A Review task is still open');
return;
}
else{
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");
}
});
I would suggest this
1) show the UI action only when there are no active Change Tasks in Review State
If my response helped please mark it correct and close the thread so that it benefits future readers.
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader