Check fields complete when UI action selected before running

Sam Ogden
Tera Guru

Hi All,

We have a UI action of 'complete' on our change request form.   When this UI action is selected it needs to check the following:

1. Proposed change has been applied

2. if the client communication needed field is ticked (u_client_communication_needed1) and the final communication sent is not blank (u_final_communication_sent)

3. all tasks are completed

If any of the 3 are not true then the process is aborted, the user is shown back to the form with an info message explaining the issue

4 completion code has a value, if not bring up the field in a pop up to be completed.

I've tried to achieve this with the following but it is not doing anything when the UI action is clicked:

Any help is greatly appreciated

find_real_file.png

function checkproposedchange(){
var pc = new GlideRecord('task_ci');
pc.addQuery('task',current.sys_id);
pc.query();
while (pc.next())
if (pc.applied != true){
gs.addInfoMessage(gs.getMessage('The proposed change must be applied before the change request can be completed'));
}
}

function checkchgtskcreated(){

var chgtsk = new GlideRecord('change_task');
chgtsk.addQuery('change_request',current.sys_id);
chgtsk.addQuery('active',false);
chgtsk.query();
if(!chgtsk.next())
  {
  gs.addInfoMessage("Please complete all tasks before completing the change request");
  current.setAbortAction(true);
  }
}

if(current.u_client_communication_needed1 == true && current.u_final_communication_send == ""){
gs.addInfoMessage(gs.getMessage('Client communication needs sending before the change request can be completed'));
}

current.setAbortAction(true);
action.setRedirectURL(current);

function makemandatecomplete()
{
var comp_code= g_form.getValue("u_completion_code");
var comp_notes = g_form.getValue("u_completion_notes");
if (comp_code == "" && comp_notes == "")
  {
  var gdw = new GlideDialogWindow('u_change_complete');
  gdw.setTitle('PIR Details');
  gdw.setSize(400,300);
  gdw.setPreference('client_comm' , g_form.getValue('u_client_communication_needed1'));
  gdw.render();
}
else{
  g_form.setMandatory('work_end',true);
  g_form.setMandatory('u_completion_code',true);
  g_form.setMandatory('u_completion_notes',true);
  gsftSubmit(null, g_form.getFormElement(), 'complete');
}

}
if(typeof window == 'undefined')
runcode();
function runcode()
{

  current.state = '6';
//current.setWorkflow(false);
current.u_completion_time = gs.nowDateTime();
current.update();
action.setRedirectURL(current);

}

8 REPLIES 8

Yes. Same outcome, but smarter and easier to build/maintain.



By moving the related table checks (applied changes and tasks complete) to the condtions and calling them from a script include, the Complete button won't appear because the related information is not done. That's not something the user can do from that form anyway, so you don't need/want the button available at that time.



Now all the button has to do in the client script is check that the checkbox is checked and warn if it isn't. If it is, then go ahead and process the rest of the stuff in the server side code.


Sharique Azim
Mega Sage

Hi,



sorry your code   is highly unformatted . But first thing first, the   client script function would not   support server side code current for example..


tip:Use     the client code for checking basic things on the form and use the   rest portion to execute the server side code.


Also, use glidewindow outside the client code.


Hi Sharique,



Thanks for the above information.   I was fully expecting it to be a mess, I'm new to coding and still make lots of stupid mistakes.



Could you show how you meant about checking the basic things in the client code and the rest portion to execute the server side, not sure what I need to do to format the code correctly



Appreciate all your help



Thanks


Sam


Hi Sam,



Could you show how you meant about checking the basic things in the client code and the rest portion to execute the server side,



What i mean here is that checking things like as mentioned "2. if the client communication needed field is ticked (u_client_communication_needed1) and the final communication sent is not blank (u_final_communication_sent)" is verified from the form,   the gliderecord things should be done outside client side code.