Make field mandatory

Abdul
Tera Contributor

Hi

 

Whenever the below "Dispatch" field  is read only then the field named Part Information should be made mandatory.

And Dispatch field gets to be readonly when the form is saved.

So when the dispatch field is checked the part information should not be visible and only when the form gets saved and the dispatch field is read only the part information field is made visible and mandatory

How can we do that

Abdul_0-1759294531544.png

 

1 ACCEPTED SOLUTION

svirkar420
Tera Guru

Hi @Abdul , try the onLoad script below, if this is on catalog form then use catalog client script

Script:

 

function onLoad() {
var dispatchField = 'dispatch';
var partInfoField = 'part_information';

var isDispatchChecked = g_form.getValue(dispatchField) == 'true';
var isDispatchReadOnly = g_form.isReadOnly(dispatchField);

if (isDispatchReadOnly && isDispatchChecked) {
g_form.setVisible(partInfoField, true);
g_form.setMandatory(partInfoField, true);
} else {
g_form.setVisible(partInfoField, false);
g_form.setMandatory(partInfoField, false);
}
}

 

If this solution helps you please don't forget to mark this solution as accepted and helpful, this will help others as well.

Regards,

Saurabh V.

 

View solution in original post

4 REPLIES 4

GauravK47713977
Tera Contributor

Hi Abdul,

 

Try to use 'onload' Client script and create necessary condition to check if the field is readOnly. If the field is readOnly make the other field Mandatory

 

function onLoad() {

  var depatchField= 'depatch_field';
  var partInfoField= 'part_info_field';

  var isReadOnly = !g_form.isEditableField(depatchField);
  g_form.setMandatory(partField, isReadOnly);
}

 

Please like the feedback if the solution proposed is helpful for you.

 

i wrote the below code it makes it mandatory whenever the form loads, this field should only be mandatory and visible if the condition such as dispatch check box is true and it is read only. 

function onLoad() {
   //Type appropriate comment here, and begin script below
if(g_form.isReadOnly('x_pfr_orts_integra_dispatch'))
{
    g_form.setVisible('u_part_information',true);
    g_form.setMandatory('u_part_information',true);
}

}

svirkar420
Tera Guru

Hi @Abdul , try the onLoad script below, if this is on catalog form then use catalog client script

Script:

 

function onLoad() {
var dispatchField = 'dispatch';
var partInfoField = 'part_information';

var isDispatchChecked = g_form.getValue(dispatchField) == 'true';
var isDispatchReadOnly = g_form.isReadOnly(dispatchField);

if (isDispatchReadOnly && isDispatchChecked) {
g_form.setVisible(partInfoField, true);
g_form.setMandatory(partInfoField, true);
} else {
g_form.setVisible(partInfoField, false);
g_form.setMandatory(partInfoField, false);
}
}

 

If this solution helps you please don't forget to mark this solution as accepted and helpful, this will help others as well.

Regards,

Saurabh V.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Abdul 

is that Dispatch field already readonly and no one will be changing that?

If yes then you can use onLoad client script

If not then you can use onChange on that checkbox

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader