How jQuery works in catalog client script

krishna343
Tera Contributor

Hi,

 

I am trying to understand, how the jQuery is working in the below script screenshot

trying to find the "app_role_checkbox_val" where i can see it

krishna343_0-1671549629382.png

 

 

11 REPLIES 11

@krishna343 

"app_role_checkbox_val" is a class in DOM.

So jQuery is reading all the elements in the DOM where the class is "app_role_checkbox_val". and looping through each element using each function.

Getting the element id of each element and pushing it to an array.

Then after that setting the array value to "app_roles" field.

 

Please mark as correct answer if this answers your question

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi @jaheerhattiwale 

i can see  only sometimes values are populating in the app_roles  , is there any way to track on which bases these element ids are populating

@krishna343 If jQuery don't find "app_role_checkbox_val" class in DOM then it will not work.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale , how "app_role_checkbox_val" class is available in dom, is there any conditions?

 

@krishna343 

Do "Ctrl+Shift+i" on the form

Search "app_role_checkbox_val" in Elements

jaheerhattiwale_0-1671553161339.png

If it is present then you will see it in elements

If it is present then it should populate the app_roles field

 

If its present and then also not populating then add some delay to make DOM load completely

 

for that change code as below

 

setTimeout(function(){

//Add you jQuery code here

}, 5000);

 

Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023