What is the alternate for gel() in client script

ramesh_r
Mega Sage

Hi All,

 

I have the client script with the gel() method but I want to replace gel() with something else.

Please help me with an alternate for gel() in the client script

Sample Line below:

var name = gel('service_select_0'));

 

Thanks

 

 

8 REPLIES 8

There's not a 1 on 1 replacement. You really have to look at the individual cases, what your developers have setup, what the functionality is, if you can rebuild such, or that you have to abandon the functionality, etcetera.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Probably the first time I am seeing anyone use etcetera and not just etc. 🙂

-Anurag

You are looking to find alternate of gel(), which is not recommended, basically DOM manipulation is not recommended, so any alternate you use for the same, it will still not be a good practice.

For eg, stealing is bad, what is the alternate - There is no alternate just don't steal.

 

As Mark rightly said, depends on the case what you are trying to do , in many cases you can find an OOB api for the same, eg to show / hide fields, field styles, field behavior , all these can be done in javascript using get() but servicenow has alternate functions to control this in g_form api.

-Anurag

sumanta pal
Kilo Guru

Sure, you can replace the gel() method with the getElementById() method. Here's how you can do it: - The gel() method in ServiceNow is a global method that is used to get the HTML element by its ID. It is similar to the JavaScript method document.getElementById(). - However, the gel() method is not officially supported by ServiceNow and it is recommended to use the officially supported methods instead. - You can replace the gel() method with the document.getElementById() method in your client script. Here's the modified line of your code: javascript var name = document.getElementById('service_select_0'); - This line of code will do the same thing as your original line of code. It will get the HTML element with the ID 'service_select_0' and assign it to the variable 'name'. - Remember to remove the extra closing parenthesis at the end of your original line of code. It seems to be a typo. The correct syntax does not include this extra parenthesis.