Why is my UI Policy not working with the OnLoad client script that I created?

Cupcake
Mega Guru

I have a catalog form where I created an onLoad client script just to filter the list collector. In addition, I have a UI policy setup to only show the list collector if one of the variables is = true.

The onLoad client script works in reference to filtering the list based on the u_org, but UI policy is not applying (it is showing the list ALL of the time).

find_real_file.png

find_real_file.png

I've already tried so many variations but I can figure out why for the life of me this thing is not working.

Thanks,

karen

3 REPLIES 3

Uncle Rob
Kilo Patron

I generally avoid client scripts and UI policies on the same field.   Been burned too many times.



Have you tried putting this all in one Client Script?   You'd have to convert it to an OnChange type (if I'm understanding your use case correctly).   You can still factor for what happens on load with the "isLoading" ...



function onChange(control, oldValue, newValue, isLoading, isTemplate) {



    if (isLoading)


    return;


Thank you for your comment. So should my script look like the below (not really sure where to apply the if (isLoading) portion



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading)



            return;


}


                            //Apply a default filter to the list collector variable


    var collectorName = 'aedwdb_request'; //you need your variable name here


    var filterString = 'u_org=AEDW';


    //Hide the list collector until we've set the filter


    g_form.setDisplay(collectorName, false);


    setCollectorFilter();



                            function setCollectorFilter(){


                            //Test if the g_filter property is defined on our list collector.


          //If it hasn't rendered yet, wait 100ms and try again.


          if(typeof(window[collectorName + 'g_filter']) == 'undefined'){


                setTimeout(setCollectorFilter, 100);


                return;


          }


                                                          //Find the filter elements


          //var fil = gel('ep');


          //Hide the filter elements by un-commenting the following lines


          /*fil.rows[0].style.display = 'none';


          fil.rows[1].style.display = 'none';


          fil.nextSibling.rows[0].style.display = 'none'; //Filter description text*/


          //Reset the filter query


          window[collectorName + 'g_filter'].reset();


          window[collectorName + 'g_filter'].setQuery(filterString);


          window[collectorName + 'acRequest'](null);            


          g_form.setDisplay(collectorName, true);


                                }


    }


If I understand that you want to hide the list collector unless another variable is populated, I'd put that hiding logic in the if statement that checks for isLoading.



Then make sure your onChange is targeting the field who's value controls whether to expose the list collector or not, and you'll need an if statement to control that too.



Make sense?