Restrict change closure if there are open tasks

ramkrish
Kilo Contributor

Hi,

I have coded as per below in an before update BR.

var task=new GlideRecord('Change_Task');

  task.addJoinQuery('change', current.number,'change_task.number');

  task.query();

  while (task.hasnext())

  {

  if (task.state != 'Closed Complete')

  gs.addErrorMessage('Ticket cannot be moved to Closed');

  }

But it is not working. Can you help here?

10 REPLIES 10

Hi ramkrish,



If I have answered your question, would you mind marking my Answer as Correct and close the thread? So that it can be tracked later by others in need.


Hi ramkrish ,



May I know the status of this thread? Please mark my Answer Correct, if you already got the solution.


vinitha3
Tera Guru

Hi,



On Close UI action you can do this check, this works in our instance.



function moveToClosed(){



  var ch_id =   g_form.getUniqueValue();  


  //alert(ch_id);


  var task_stat;


  var diff;


  //check for change tasks. They need to be closed before a change is closed


  var ch_task = new GlideRecord('change_task');


  ch_task.addQuery('change_request',ch_id);


  ch_task.query();


  while(ch_task.next())


  {


  task_stat = ch_task.state;


  if(task_stat != '3')


  {


  alert('Please close the change tasks - '+ch_task.number +' before the change request is closed.');


  diff='1';


  }


  }



  if(diff != '1')


  {


  g_form.setMandatory('close_code',true);


  g_form.setMandatory('close_notes',true);



  var ga = new GlideAjax("ChangeRequestStateHandlerAjax");


  ga.addParam("sysparm_name", "getStateValue");


  ga.addParam("sysparm_state_name", "closed");


  ga.getXMLAnswer(function(stateValue) {


  g_form.setValue("state", stateValue);


  gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");


  });


  }


}




if (typeof window == 'undefined')


  {


  //updateinc();


    setRedirect();


  }




function setRedirect() {




      current.update();


      action.setRedirectURL(current);


}



Thanks,


VInitha.K


Thanks Vinitha.


I have small doubt on the way the GlideRecord is used as below.


find_real_file.png


Is this part of client script or server side script?


Hello,



On Close UI action, so both client and server are managed in the code, This is up and running in our instance.



find_real_file.png


Thanks,


Vinitha.K