UI policies/Client scripts too slow

vibee
Kilo Expert

Hi,

I am trying to use UI polices or client scripts to hide values on a catalog order guide. But when I go to the pages, and catalog items, it lags when the page loads, and I can see the values briefly before they hide. Is there a way to hide the items without causing this slowdown in loading the page? I don't want users to get confused when they see the fields before it hides, can I speed this up somehow so that page loads without anyone seeing the values before the UI policies/client scripts kick in? Same issue happens on the catalog order page as well.

12 REPLIES 12

Umar M
ServiceNow Employee
ServiceNow Employee

Unfortunately there is no way of doing that, I'm not sure what version of SN you are on but there is a good post on SNGuru that details the process of using a loading dialog to prevent and user interaction before a form loads. Unfortunately it looks as though it might not work on Fuji.


Solving the Client Script 'Before and After' Problem - ServiceNow Guru



Are you using any server side calls in any of these client scripts?


They are all onLoad scripts to modify a list collector...no calls to any other table, except for one that filters the values within the list.


BryanS413339635
Tera Guru

Synchronous ajax calls perhaps? Try cleaning up your client scripts by following the Best Practices outlined here: Client Script Best Practices - ServiceNow Wiki



Here are the 3 scripts I am running:


Filter Locations:


function onLoad() {


    //Apply a default filter to the list collector variable


    var collectorName = 'yardi_res_other';


    var filterString = 'u_yardi_code!=NULL^ORnameLIKECorporate';


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


          //Redisplay the list collector variable


          g_form.setDisplay(collectorName, true);


    }


}



List Collector Header name change:


function onLoad() {  


var slushHeaders2 = g_form.getControl('yardi_res_other').parentElement.querySelectorAll('.col-xs-4');      


// change the 'comsoft_list' part to the name of wtvr list  


var checkForList = function(){  


if(typeof group_bucketg_filter !== 'undefined'){  


configureList();  


}else{  


setTimeout(checkForList,250);  


}  


};  


 


var configureList = function(){  


// this sets the filtered list  


group_bucketg_filter.reset();  


group_bucketg_filter.setQuery('active!=false');  


group_bucketacRequest(null);  


};  


 


checkForList();  


// set the slush bucket headers    


slushHeaders2[0].childNodes[0].firstChild.data = 'List of Residences';  


slushHeaders2[1].childNodes[0].firstChild.data = 'Chosen Residences';    


}



Resize List Collector width:


function onLoad() {


    //Type appropriate comment here, and begin script below


  document.getElementById("yardi_res_other_select_0").style.maxWidth = "500px";


  document.getElementById("yardi_res_other_select_0").style.width = "470px";


  document.getElementById("yardi_res_other_select_1").style.maxWidth = "500px";


  document.getElementById("yardi_res_other_select_1").style.width = "470px";


}


I don't know that it will help too much, but try replacing the first script (filter locations) with this one:



function onLoad() {


   


    addLateLoadEvent(function () {


          yardi_res_other_filter.setQuery('u_yardi_code!=NULL^ORnameLIKECorporate');


          yardi_res_otheracRequest();


    });


}




And perhaps you could combine the 2nd and 3rd scripts?