Mandatory and read only fields after save

scottjus82
Kilo Guru

Hey all,

 

I now have a requirement to lock fields, make them mandatory and unlock depending on states and wondered what the best/quickest approach would be below is the flow and what locks/mandatorys are needed

 

 

When the phase is in definition nothing is mandatory. this is a draft phase and at this point the user can save, request 4 eyes check and delete the record. Once 4 eyes is requested all fields are locked down other than the one for the name of the 4 eyes checker and if its approved or not. Once approved fields are no longer locked and the majority of them become mandatory. I had thoght a simple UI policy would be fine but that makes fields mandatory as soon as the 4 eyes approves. They should only be mandatory once the change is saved as it will be someone else populating those fields. With the different locks,unlocks and mandatory s I wondered how others have done it. My initial thought was a hidden check box that ticks once 4 eyes is done I then base my UI policy on that tick box.

 

 

Any thoughts?

1 ACCEPTED SOLUTION

function onLoad() {


    var phase = g_form.getValue('phase');



    if (phase == 'Waiting Technical Review') {


  g_form.setMandatory('u_4eyes_checker', true);


  g_form.setMandatory('u_4eyes_completed', true);


  g_form.setReadonly('start_date', true);


  }


}


View solution in original post

15 REPLIES 15

function onLoad() {


    var phase = g_form.getValue('phase');



    if (phase == 'Waiting Technical Review') {


  g_form.setMandatory('u_4eyes_checker', true);


  g_form.setMandatory('u_4eyes_completed', true);


  g_form.setReadonly('start_date', true);


  }


}


Hi Daryll,



Thanks for this, it is almost working. the only thing that's wrong is the


start date is not read only. i have double checked I am using the right


field name and I am so I cant see why its not firing.



Regards



On 6 November 2014 12:23, Daryll Conway <community-no-reply@servicenow.com>


I think you can use both but try setReadOnly.


Also check that the fields read only property isn't being set by a ui policy or another script


thank you @Daryll Conway 

=! should be != and state is not declared in this line


if (state == 'Waiting Technical Review' )