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

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Peter,



Not sure what you are after here. But the switchView functionality for for switching a view for a modal. Doesn't really seem to be the functionality here you are after.



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GMODV3-switchView_S


Thanks for your comments


Kamal17
Kilo Sage

Hi Peter,



When your onload script executes, the switchView() function will re-load/referesh the form while switching the view, this results in your onLoad script to execute again and this behavior causes infinite loop. To avoid this you can try using switchView() in onChange client script.



-Udhay


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


Yes, As your recommend I have changed OnChange but it seem not a best way to do because when I change value on field it pop up verify windows.but if you check function in isLoading it also happen the same with OnLoad.