How to stop Infinite loop onLoad with view list?

Peter Tran2
Kilo Contributor

I have create new client script to switch view base on title field on sys_user table. But it seem switch infinite loop view list not specific view base on condition

How can I stop infinite load

below my script:

function onLoad() {

var employee = g_form.getReference('u_employee_name');

if(employee.title == 'Employee' || employee.title == 'Supervisor'){

switchView('section','u_incident_log','basic_view');

}

else if(employee.title == 'Manager') {

switchView('section','u_incident_log','Self_service');

}

else if(employee.title == 'Site Mgr' || employee.title == 'Vice President') {

switchView('section','u_incident_log','site_mgr_vp');

}

else{

switchView('section','u_incident_log','');

}

}

find_real_file.png

1 ACCEPTED SOLUTION

Hi Peter,



You can use onLoad client script for your requirement but should include some changes to avoid infinite loop. Please refer the below screenshot,



find_real_file.png



Just make sure the view names and case sensitivity are correct.



-Udhay


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

10 REPLIES 10

Hi Uday



i am working on jakarta version,



i have written script for form view Onchange   it is working fine, but if i comes to OnLoad   it is not working well, could you please suggest on this



From List of Records when   form opened - OnLoad     loaded mean if state != closed then display Default View,


and                                                                             If state== closed then display view 'state_closed' view




if(g_form.getValue('state') == 7)


{


var strView = document.getElementById('sysparm_view').value;


    switchView('section','incident','state_closed');


}


else


{


switchView('section','incident',' ');


}


        OR



var currentview = document.getElementById('sysparm_view').value;


var newView=" ";



if(g_form.getValue('state') == 7)


{


newView='state_closed';


}


      else if(g_form.getValue('state') != 7)


{


newView= ' ';


}



if(currentview!=newView)


{


switchView('section','incident',' ');


}


                  else


  {


 


  }