Check box field mandatory

samadam
Kilo Sage

I need to make check box field mandatory at certain state, I am trying with this script to not allow without checked but doesnt work

    var bd = g_form.getValue('u_shipment');
    var rec_state =  g_form.getValue('u_state');
    if (!g_form.getValue('u_shipment') && rec_state == 'ship') {
        g_form.addErrorMessage('Shipment must be checked to continue');
    return false;
    }
tried to add alert no luck. Any ideas?
3 REPLIES 3

Paul Curwen
Giga Sage

Presuming your field u_shipment is a True/False type and it's Default value is set to false change this line:

 

if(!g_form.getValue('u_shipment') && rec_state =='ship') {

 

to: 

 

if (g_form.getValue('u_shipment') == 'false' && rec_state == 'ship') {

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Robbie
Kilo Patron
Kilo Patron

Hi @samadam,

 

You have a couple of options available for you depending on whether this is a checkbox on a Catalog Item (a variable) or is it's a checkbox field on a task table such as Incident for example.

 

For a Catalog variable: Leverage the "Selection required" checkbox on the variable form

For a table that extends task: g_form.setMandatory('checkbox_field_name', true);

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

 

 

var bd = g_form.getValue('u_shipment');
var rec_state =  g_form.getValue('u_state');
if (!g_form.getValue('u_shipment') && rec_state == 'ship') {
    g_form.setMandatory('u_shipment', true);
    g_form.addErrorMessage('Shipment must be checked to continue');
    return false;
}

 

Tried both suggestions and did not work. This is a custom table. It behaves as if it doesnt hit the OnSubmit script