How to make Serial Number mandatory according to Model Category selection

Kentaro Numata
Tera Guru

Hi, There. It's Ken.

 

I want to require Serial Number depending on the Model Category selection.

I want to make Serial Number mandatory when Computer and Smart Device are selected in Model Category.

 

First, I created a UI Policy to make it a mandatory input.
However, I found that it conflicted with "MC - Make serial number mandatory" in Client Script.
I have confirmed that the UI Policy works by deactivating "MC - Make serial number mandatory".

 

I would prefer not to deactivate "MC - Make serial number mandatory".

After code analysis, it seems that the Model Category parameter is checked.

Please tell me how to make Serial Number mandatory when Computer and Smart Device are selected in Model Category.

 

Thanks,

Ken.

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage
Mega Sage

Hi @Kentaro Numata ,

 

You can achieve this by using a client script that runs on the form load event and checks the value of the Model Category field. If the selected value is Computer or Smart Device, then make the Serial Number field mandatory using the setMandatory() function. Here's an example script:

function onLoad() {
    var modelCategory = g_form.getValue('model_category');
    if (modelCategory == 'computer' || modelCategory == 'smart_device') {
        g_form.setMandatory('serial_number', true);
    }
}

 

Thanks,

Ratnakar

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @Kentaro Numata ,

 

You can achieve this by using a client script that runs on the form load event and checks the value of the Model Category field. If the selected value is Computer or Smart Device, then make the Serial Number field mandatory using the setMandatory() function. Here's an example script:

function onLoad() {
    var modelCategory = g_form.getValue('model_category');
    if (modelCategory == 'computer' || modelCategory == 'smart_device') {
        g_form.setMandatory('serial_number', true);
    }
}

 

Thanks,

Ratnakar

Neeraj_27
Tera Guru

Hi @Kentaro Numata ,

Can you confirm whether serial number should be mandatory only when Computer and Smart Device are selected in Model Category? and check the order of the Client script which make the serial number mandatory?

If it is the requirement then write a Ui policy on the model category, and in conditions specify Model Category field "is not" computer or smart device. And in ui policy action add the serial number and make mandatory false. As the Ui policies executes after the Client script it make the serial number non mandatory for all conditions

or else go for the same client script which make the serial number mandatory and specify the conditions as above @Ratnakar7 mentioned.