Difference between gr.getValue('fieldname') vs gr.fieldname vs gr.fieldname.getValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 08:58 PM
Hi Team,
I have read few posts to understand the difference between gr.getValue('fieldname') vs gr.fieldname vs gr.fieldname.getValue() but I'm not clear when to you or what the advantages are of using one over the other.
var gr = new GlideRecord("incident");
var logQ = [];
gr.addEncodedQuery("opened_at>=javascript:gs.dateGenerate('2022-11-14','16:36:44')");
gr.orderByDesc("number");
gr.query();
while (gr.next()) {
logQ.push("The Priority is " + gr.priority + " The Getvalue is " + gr.getValue("priority") + " " + gr.priority.getValue());
}
for(i=0;i<logQ.length;i++){
gs.print(logQ[i]);
}
In the above code, when I printed the values, all 3 brought in proper backend values, so I would appreciate if you can help me understand.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 09:26 PM
Hello this link will be helpful to understand why we use getValue ().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2023 09:44 PM
Hi @JohnnySnow ,
gr.getValue('fieldname') gives you the string representation of the field while gr.fieldname returns the GlideElement object (depending on field type it can vary from string,integer etc)
Refer below link for more details