Script not working Script Include and UI Action in Change Request

win b
Mega Guru

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.

find_real_file.png
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.
find_real_file.png
here is my UI Action were i get the value from my Script Include

find_real_file.png
here is what i got false answer wherein its supposed to be true because my task Review type state is Open

find_real_file.png
here is my another ticket wherein my Review Task State is closed which is correct way i supposed to be expecting.

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

win b
Mega Guru

Hi @Ankur Bawiskar  i got a question on 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();
	
},
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?

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader