Script in UI Policy is not working

ronro2
Tera Contributor

Hi guys!

I have a UI policy that is messing up. I thought I would try scripting the UI policy instead to see if that would fix the problem.

I have a multiple choice variable 'order_type' and another variable called 'cluter_name'.

It should read like this:

- when 'order_type' is 'change', 'cluster_owner' should be visible but not mandatory.
- when 'order_type' is 'new_environment', 'cluster_owner' should be visible + mandatory.

-When 'order_type' is 'decommissioning' then 'cluster_owner' should be hidden.
- If all choices are empty, that is, if order_type is neither 'change', 'decommissioning' or 'new_environment', 'cluster_owner' be hidden by default.

I see that this syntax is in the script boxes for If true and If false, and I assume it should be used:
function onCondition() {

}

This is my script in the Execute if true script box, which is not working, except for hiding cluster_owner as default (that part is the only thing working):

 

function onCondition() {
    var orderType = g_form.getValue('order_type');
    var clusterOwner = 'cluster_owner';

    if (orderType === 'change') {
        g_form.setDisplay(clusterOwner, true);
        g_form.setMandatory(clusterOwner, false);
    } else if (orderType === 'new_environment') {
        g_form.setDisplay(clusterOwner, true);
        g_form.setMandatory(clusterOwner, true);
    } else if (orderType === 'decommissioning') {
        g_form.setDisplay(clusterOwner, false);
    } else {
        g_form.setDisplay(clusterOwner, false);
    }
}

 

 
Any ideas why? 

4 REPLIES 4

Viraj Hudlikar
Giga Sage

Hello @ronro2 

 

Your scripts seem fine to me at first glance. Add some log statements to check the values of orderType and ensure the script is executing as expected.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Medi C
Giga Sage

Hi @ronro2,

 

This can be achieved by 3 UI Policies without scripting.


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

ronro2
Tera Contributor

Why I chose to script is due to show Info only when 'change' is selected. 

maddalahemanth
Tera Contributor

Hii @ronro2 ,

I think you can achieve this through UI Policy Actions.

Here you are using the script but in that you have used setDisplay() instead of it you can use setVisible() to make visible a field on the form.

Try this and let me know it would help you fine or not.