How to make work notes mandatory on clicking 'Close Task' button

bhoomikabisht
Kilo Expert

Hi Experts,

I am working on Change task form. I have created a UI Policy to make Work Notes mandatory when the State is Closed Complete and it is working fine. But the problem is when I click on Close Task button, it is closing the task without prompting that Work Notes are Mandatory.

I am trying to make it mandatory in Close Task Ui Action. But it is not working.

Please help me to achieve this.

Thanks & Regards,

Bhoomika Bisht

12 REPLIES 12

Ajai S Nair
Giga Guru

Hi Bhoomika,


Try something like this in the UI action:



if (!current.close_notes.nil()) {


current.state = 3;


current.update();


} else {


gs.addErrorMessage("Please update the close notes field prior to closing the task.");


action.setRedirectURL(current);


}


karthiknagaramu
Kilo Sage

Hi Bhoomika,



It would require to modify the UI Action. Below code snippet is from Resolve Incident, this UI Action makes the Comments mandatory when user click on Resolve Incident.


function resolveIncident(){


    //Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields


    g_form.setValue('incident_state', 6);


    g_form.setValue('state', 6);



    if (g_form.getValue('comments') == '') {


          //Remove any existing field message, set comments mandatory, and show a new field message


          try {g_form.hideFieldMsg('comments');} catch(e) {}


          g_form.setMandatory('comments', true);


          g_form.showFieldMsg('comments','Comments are required when resolving an Incident','error');


          return false;   //Abort submission


    }


    //Call the UI Action and skip the 'onclick' function


    gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action


}



Check above highlighted code. You would need to write code similar to this for work notes.



Regards,


KN


madanm7786
Mega Guru

Hi Bhoomika,



Please convert your ui policy to data policy. You will find the related link "Convert UI policy to data policy" in the UI policy you have created. This will work.



Thanks,


Madan


arnabwa
Giga Guru

Hi Bhoomika,



That is a really very important enhancement for a Snow developer. You have to make UI Action with client side validations . Try this code I wrote it for you and also tested successfully :



close1.PNG


Copy paste the below code and it works perfectly well :



function closeTask(){     // This function is called when we click on the button to execute certain client side codes.


if (g_form.getValue('work_notes') == '') {


  // Remove any existing field message, set comments mandatory, and show a new field message


  try {


  g_form.hideFieldMsg('work_notes'); // Client side execution : hiding field messages in Comments field if any


  } catch(e) {}


  g_form.setMandatory('work_notes', true); // Client side execution : setting mandatory


  g_form.showFieldMsg('work_notes', getMessage('Please enter Work Notes before closing the Task'), 'error'); // If you want the approver to describe the changes he needs.Client side execution


  return false;   // Abort submission


}


gsftSubmit(null, g_form.getFormElement(), 'close_task'); // MUST call the 'Action name' set in this UI Action


}


// Code that runs without 'onclick' . This is the server side code all below and outside the Onclick function because you need to execute this on the server side


if (typeof window == 'undefined')


  serverReopen();



function serverReopen() {


  current.state = 3;


  current.update();


  action.setRedirectURL(current);


}



This is how it looks in a screenshot :


close2.PNG





Thanks,


Arnab



Please mark Correct/Helpful according to the worthiness of my explaination. Thank you in advance.