Setting a field mandatory in Onload client script

samadam
Kilo Sage

I have a n onload client script where I am checking the state and setting a field mandatory but it is not working. There are no UI policies on this field. I dont even get the alert in the beginning of the script I added.

var st = g_form.getValue('u_state');
    alert(st);
  if (st == 'Draft'){
        g_form.setMandatory('u_ship', true);
  }
1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Check the console in your browser's developer tools.  I'm guessing there's an error somewhere else that's stopping this script from running.

 

Once you figure that out, it's probably a good idea to switch over to a UI Policy to set it mandatory.

View solution in original post

6 REPLIES 6

@samadam If you need to make field mandatory on the state change, then you need to create an onChange script on the State field. onLoad script only gets called when the form loads whereas the onChange script gets called whenever there is a change in the value of a specific field.

 

Hope this helps.

samadam
Kilo Sage

Figured it out, There was a premature closure of a ")" which caused it. Once I fixed that it started working. Thank you. I am surprised how the script saved successfully.