what is the difference between getElemet and getValue

Prasanthi1
Giga Contributor

What is the difference getElement() and getValue()?

Please tell me with examples..

1 ACCEPTED SOLUTION

Sushma Dhandge
Giga Contributor

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

View solution in original post

9 REPLIES 9

Murthy Ch
Giga Sage

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

Thanks,
Murthy

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?

Hi Prasanthi,

 

We prefer mostly getValue() in all cases.

 

Thanks,

Murthy

 

Please mark my answer helpful if its solves your query.

Thanks,
Murthy

Sushma Dhandge
Giga Contributor

 

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.

 

Regards,

Sushma