how to use gel in servicenow

shank1
Tera Expert

Hi all,

I wanted to know how to make use of gel in servicenow.

Some of the lines I have come across:

1.
com = gel("activity-stream-comments-textarea"); if (com) com.focus(); return;

2. gel('sysparm_item_guid').value

so I wanted to know what are those values "activity-stream-comments-textarea" and ''sysparm_item_guid'"

how and where those values can be found and used.

any other simple example to make use of gel would be greatly helpful

 

thanks in advance 🙂

 

 

 

1 ACCEPTED SOLUTION

Paul Curwen
Giga Sage

Hi Shanks,

 

Rahulpandey is correct in stating that use introduces risk to future upgrades and be aware that that getElementbyID(''element') will not work in Service Portal at all, so you should not use it for Catalog Scripts etc.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/build/service-portal/concept/uns...

So avoid using if you can but if you absolutely must, then see these useful articles for full description of use/issue:

https://snprotips.com/blog/2017/7/21/how-to-enable-dom-manipulation-in-the-servicenow-service-portal

http://www.snc-blog.com/2011/03/03/altering-the-dom-document-object-model-with-javascript/

 

Regards,

 

Paul

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

View solution in original post

9 REPLIES 9

rahulpandey
Kilo Sage
Hi, gel is same as getElementbyID(''element'). This is generally to manipulate the HTML. Let me say this, service now do not encourage to use this way of manipulation (dom manipulation) because I'd of any element can change with version upgrade. activity-stream-comments-textarea :- this gives you value of activity-stream-comments-textarea field gel('sysparm_item_guid').value same goes to this. Useage of these values depends on logic you are applying. Check this https://www.w3schools.com/jsref/met_document_getelementbyid.asp

shank1
Tera Expert

Hi Rahul, 

Yes I know that its not recommended. but I just wanted to know how it works.

How can I get the element ID of a particular field.

TIA

You can open browser developer tool(F12) and you can see all the elements their attributes (including I'd).

Paul Curwen
Giga Sage

Hi Shanks,

 

Rahulpandey is correct in stating that use introduces risk to future upgrades and be aware that that getElementbyID(''element') will not work in Service Portal at all, so you should not use it for Catalog Scripts etc.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/build/service-portal/concept/uns...

So avoid using if you can but if you absolutely must, then see these useful articles for full description of use/issue:

https://snprotips.com/blog/2017/7/21/how-to-enable-dom-manipulation-in-the-servicenow-service-portal

http://www.snc-blog.com/2011/03/03/altering-the-dom-document-object-model-with-javascript/

 

Regards,

 

Paul

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul