change should Not be allowed to put in Implement State before Planned Start Date

krishna111
Tera Contributor

Hello All,

 

Hope all are doing fine!!

In change module UI action "implement " when clicked we observed that we were able to move a change to Implement state before the Scheduled Planned Start Date/Time. In actual scenarios, this is not a good practice in terms of ITSM guidelines.

Currently there was no checks for it in the ui action script i modified the script as below now when i click on the ui action nothing happens it wont do anything can anyone advise on this.

 

function moveToImplement() {
    // Check if the planned start date is in the future
    if (g_form.getValue("planned_start_date") > new GlideDateTime()) {
        // Planned start date is in the future, show an error message
        alert("Cannot change to Implement state before Planned Start Date.");
    } else {
        // Planned start date is in the past or present, proceed with the state change
        g_form.setValue("state""-1");
        gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
    }
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}
 
Thanks
Krishna
1 ACCEPTED SOLUTION

Namrata Ghorpad
Mega Sage
Mega Sage

Hi @krishna111 ,

Update UI action "Implement" on change_request table like below.

function moveToImplement() {
	
	g_form.setValue("state", "-1");
	gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
}

if (typeof window == 'undefined')
	var pldate=current.start_date;
	gs.addInfoMessage(pldate);
	var dt=new GlideDateTime();
	var plannedDate= new GlideDateTime(pldate);
	var diff=plannedDate.getNumericValue()-dt.getNumericValue();
	gs.addInfoMessage(diff);
	if(diff>0){
		gs.addInfoMessage("you can not implement change before start date");
		current.setAbortAction(true);
	}
	else
		{
		setRedirect();	
		}
   

function setRedirect() {
	
    current.update();
    action.setRedirectURL(current);
	
	
}

 

Please mark my answer as helpful and correct if it helps to solve your issue.

Regards,

Namrata

View solution in original post

4 REPLIES 4

Namrata Ghorpad
Mega Sage
Mega Sage

Hi @krishna111 ,

Update UI action "Implement" on change_request table like below.

function moveToImplement() {
	
	g_form.setValue("state", "-1");
	gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
}

if (typeof window == 'undefined')
	var pldate=current.start_date;
	gs.addInfoMessage(pldate);
	var dt=new GlideDateTime();
	var plannedDate= new GlideDateTime(pldate);
	var diff=plannedDate.getNumericValue()-dt.getNumericValue();
	gs.addInfoMessage(diff);
	if(diff>0){
		gs.addInfoMessage("you can not implement change before start date");
		current.setAbortAction(true);
	}
	else
		{
		setRedirect();	
		}
   

function setRedirect() {
	
    current.update();
    action.setRedirectURL(current);
	
	
}

 

Please mark my answer as helpful and correct if it helps to solve your issue.

Regards,

Namrata

Thank you Namrata,It worked like a charm.😀

Hi Namrata,

This solution which you provided works for change windows in future but its restricting the changes which are witin the change window.

example : there was a change whose start time in 4.00 am est and end time is 8.00 pm est when tried to implement the change its not allowing to implement on the above mentioned logic..anything which you can see was missed 

Thanks in advance

kumar

Hi @Namrata Ghorpad,

This solution which you provided works for change windows in future but its restricting the changes which are witin the change window.

example : there was a change whose start time in 4.00 am est and end time is 8.00 pm est when tried to implement the change its not allowing to implement on the above mentioned logic..anything which you can see was missed 

Thanks in advance

kumar