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

5 REPLIES 5

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);
}

}

lauri457
Tera Contributor
g_form.setReadOnly("field_name", !g_form.isNewRecord())

You can use the isNewRecord method from g_form to check if the form is open on a new record or existing. Not sure I follow the rest of the logic but display can be set with the setDisplay. True for show, false for hide

g_form.setDisplay("field_name", bool)

 

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.