- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 12:26 AM
What is the difference getElement() and getValue()?
Please tell me with examples..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 08:42 PM
Hi Prasanthi,
I hope below Example will clear your confusion
var gr = new GlideRecord('incident');
gr.setLimit(1);
gr.query();
gr.next();
gs.print(gr.getValue('assignment_group')); // how the direct field script looks
gs.print(gr.getValue('assignment_group.manager')); // Doesnt work
gs.print(gr.assignment_group.getValue('manager')); // Doesn't work
gs.print(gr.assignment_group.manager.getValue()) // We have to resort to the GlideElement version for dot walking
gr.getElement('assignment_group.manager').getValue(); // Closest alternative? But still using GlideElement
In the above script, we can see that the GlideRecord getValue accepts a string parameter but it can not be a dot walked field. For dot walking, we are forced to resort to the GlideElement version of getValue which does not accept a string value.
Please mark helpful if answer is correct.
Thanks,
sushma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 12:42 AM
Hi Prasanthi,
You can access a GlideElement from a server-side GlideRecord object (for example, by using gr. number ), or by using the getElement method of a GlideRecord object.
Best practice dictates that you always use the getter and setter functions: getValue() , and setValue() if you want to get the value of the field.
Pls refer this for more clarification:
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideElementDescriptorScopedAPI
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 12:52 AM
Thank you for the reply,
That means both getElement and getValue returns same no difference in that right?
Only thing is, using getValue method is the best practice.. right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 01:00 AM
Hi Prasanthi,
We prefer mostly getValue() in all cases.
Thanks,
Murthy
Please mark my answer helpful if its solves your query.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 04:25 AM
You can access a GlideElement from a server-side GlideRecord object (for example, by using gr. number ), or by using the getElement method of a GlideRecord object. Best practice dictates that you always use the getter and setter functions: getValue() , and setValue() if you want to get the value of the field.
Regards,
Sushma