To make variables mandatory when the 'closed complete' or 'closed incomplte' are clicked on a catalog task

rog
Giga Contributor

HI all,

I have a requirement where I have to make certain fields mandatory when clicked on closed complete or closed incomplete buttons on a catalog task.

I have written the following client script on the variable set:

Tyoe : onSubmit

function onSubmit() {

if(g_form.getValue('state') == '3')

{

          g_form.setMandatory("variables.var1", true);

g_form.setMandatory("variables.var2", true);

  }

}

But it is not working. please help.

Thanks

11 REPLIES 11

Suseela Peddise
Kilo Sage

Hi Roger,



Add below statement at the end of the code:



return false;



Hope this might be helpful.



If the reply was informational, please like, mark as helpful or mark as correct!


Suseela Peddise
Kilo Sage

Hi Roger,



You can also try writing a 'onChange' client script:



find_real_file.png


You can also try writing an UI policy



Hope this might be helpful.



If the reply was informational, please like, mark as helpful or mark as correct!


shloke04
Kilo Patron

Hi,



If you are having buttons on the Catalog task form for setting the state as Close Complete or Incomplete, then in order to make certain fields mandatory you need to update your UI action as mentioned below:



1) Mark the Client Checkbox on the UI Action form as true as shown in the below screenshot.


2) Provide an Action Name in the Action name field on the UI Action form and give some function name in the OnClick field on the UI Action form as shown below. This will allow you to make your UI action work both on Client as well on Server side as making fields mandate is something to be done on Client Side:




find_real_file.png


find_real_file.png



So in the above screenshot , Onclick on Close task button I am making the Description field as mandatory. You can refer the same for your Buttons.



Note: In Line Number 4 of the Script the Action Name should be same as the Action Name defined in the Action field on the UI Action form, so replace accordingly for your script.




Result:



find_real_file.png



You can refer the below link also for more details on how to use the UI Actions on both Client & Server Side:



https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

rog
Giga Contributor

Hi Suseela,



I have added return false; at the end of the code and it still didnt work.



function onSubmit() {


if(g_form.getValue('state') == '3')


{


g_form.setMandatory("variables.var1", true);


g_form.setMandatory("variables.var2", true);



return false;


}


}