UI policy script not working

Rutuja K
Giga Guru

Hi all,

 

 I have a requirement to make Change Number field on problem record visible and mandatory when Root cause code= anything and root cause subcode is Result of change and result of change subcode is not None.

 

Change Number field should be non mandatory when Root cause code= pqr.

 

I have written below UI policy script, but when evaluated false change number is not getting hidden.

Condition:  Root cause code= anything and root cause subcode is Result of change and result of change subcode is not None.

Execute if true:

function onCondition() {
    var rootCauseCode = g_form.getValue('u_root_cause_code');
alert('Evaluated True');
    g_form.setVisible('rfc', true);
    if (rootCauseCode == 'pqr') {
alert('entered if loop');
        g_form.setMandatory('rfc', false);
    } else {
        g_form.setMandatory('rfc', true);
    }
}
 
Execute if false :
function onCondition() {
alert('Evaluated False');
    g_form.setVisible('rfc', false);
    g_form.setMandatory('rfc', false);
}
1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Rutuja K ,

 

You need to make it non-mandatory first and then set the visibility, please change the execute if false script as:

function onCondition() {
alert('Evaluated False');
    g_form.setMandatory('rfc', false);
   g_form.setVisible('rfc', false);
}

 

If my answer has helped with your question, please mark it as correct ans helpful

 

Thanks!!

 

View solution in original post

3 REPLIES 3

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Rutuja K ,

 

You need to make it non-mandatory first and then set the visibility, please change the execute if false script as:

function onCondition() {
alert('Evaluated False');
    g_form.setMandatory('rfc', false);
   g_form.setVisible('rfc', false);
}

 

If my answer has helped with your question, please mark it as correct ans helpful

 

Thanks!!

 

Hi Karan,

The solution helped.

Thank you.

Bert_c1
Kilo Patron

hi,

 

your statement "...root cause subcode is Result of change and result of change subcode is not None" implies there are two other custom fields defined on the problem table. 'u_root_cause_subcode' and 'u_result_of_change_subcode'?You can test the conditions by going to a list view of problem records, and then add a filter based on your fields