getrefrecord still a valid feature to be used

Anubhav24
Mega Sage
Mega Sage

Hi All,

 

I am wondering if getreference with a callback function is still  a relevant feature which we can use or do we have something else or do we always need to use GlideAjax if we need some values from backend to frontend.

Also does it hampers the performance even if it is used in a callback function.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi @Anubhav24 - Absolutely. GlideAjax is both recommended and best practice as per the Best Practice article directly on ServiceNow's developer site: 

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/client_scripting_techni...

 

@Anubhav24 - To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

5 REPLIES 5

Robbie
Kilo Patron
Kilo Patron

Hi @Anubhav24,

 

In short, the reason why a getReference() callback is not recommended is because the method retrieves all fields in the requested GlideRecord when in most cases only one field is required (or perhaps one or 2 fields rather than all fields which can be as many as 30+ depending on the table you're querying against)

It is this additional 'weight' that adds and impacts performance. Hence the recommendation of GlideAjax.

 

Below is a link to the Best Practices directly from SN with the 'why'.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/client_scripting_techni...

Hi @Robbie  @Aman Kumar S ,

Thanks for your replies , to summarize we should keep avoiding getreference unless it becomes a necessity which in any case might not since we will be using GlideAjax.

Hi @Anubhav24 - Absolutely. GlideAjax is both recommended and best practice as per the Best Practice article directly on ServiceNow's developer site: 

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/client_scripting_techni...

 

@Anubhav24 - To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Aman Kumar S
Kilo Patron

Hi @Anubhav24 

Using getReference is still valid and used, but with awareness around using async ajax and performance impact of getRefReference people have started using ajax calls instead of sync call with callback function.

g_form.getReference just ends up calling the client-side GlideRecord API. In my opinion, client-side GlideRecord should be avoided as much as possible, since it usually results in a lot of data being transferred needlessly.

Although, in catalog due to limitation to async glideajax, getref is used if you are performing validation for onSubmit client script.

 

 

Best Regards
Aman Kumar