Dotwalked field value is not being accessed

AM24
Giga Guru

Hello,

I am attempting to dotwalk and get a value from another table in a client script. I am doing something like:

var startDate = g_form.getValue('table.approved_start_date');

alert(startDate);

My alert shows up as blank every time. I have tried it out on other fields on the table, but they have not shown up either. I did the same thing using another table that I reference, and that works perfectly. I was wondering what could be the problem since the reference field name and the desired field name are correct.

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hi AM,

You need to use the getReference method:

https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideFormAPI#r_GlideForm-Get...

You should use it with a callback function like this, inside your client script:

g_form.getReference("table", callbackFuntion);

function callbackFunction(obj){
   var date = obj.getValue("approved_start_date");
   alert(date);
}

As stated in the website I provided:

If a callback function is present, this routine runs asynchronously. The browser (and script) processing continues normally until the server returns the reference value, at which time, the callback function is invoked. If a callback function is not present, this routine runs synchronously and processing halts (causing the browser to appear to hang) while waiting on a server response.


This should work for you, but don't forget the callback function!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz



View solution in original post

5 REPLIES 5

sonali panda1
Kilo Sage
In general, dot walking is not available in client script, unless you used g_form. getReference. Even in this case, you can do dot walking only till level1. So best is to use Script Include and GlideAjax

Filipe Cruz
Kilo Sage
Kilo Sage

Hi AM,

You need to use the getReference method:

https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideFormAPI#r_GlideForm-Get...

You should use it with a callback function like this, inside your client script:

g_form.getReference("table", callbackFuntion);

function callbackFunction(obj){
   var date = obj.getValue("approved_start_date");
   alert(date);
}

As stated in the website I provided:

If a callback function is present, this routine runs asynchronously. The browser (and script) processing continues normally until the server returns the reference value, at which time, the callback function is invoked. If a callback function is not present, this routine runs synchronously and processing halts (causing the browser to appear to hang) while waiting on a server response.


This should work for you, but don't forget the callback function!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz



getReference is not best practice as it comes with performance issues.

From a DOCS Article.

Note: GlideRecord and g_form.getReference() are also available for retrieving server information. However, these methods are no longer recommended due to their performance impact. Both methods retrieve all fields in the requested GlideRecord when most cases only require one field.

As @sonali panda mentioned best practice would be to call a script include using GlideAjax.

Hello @Brian Lancaster ,

Appreciate your comment!

I would agree with you if the getReference is being used without a callback function.
As you can see in my comment, I'm fully recommending and supporting the usage of the callback function in order to make the request asynchronous. 

By stating that an Ajax call is the best approach, please, also point out that the getXMLWait should not be used and the getXML method with a callback function should be used.

Otherwise, if you compare the Ajax call + getXMLWait with a getReference with callback function, which one do you consider to have a better performance? Which one will block the browser until the server response is received? Which one will perform asynchronously?

And you can see a fairly interesting comparison of getReference, GlideRecord and ajax calls in terms of efficiency VS simplicity: (comparison made by Paul Morris, MVP)

https://community.servicenow.com/community?id=community_question&sys_id=2d08436ddb1cdbc01dcaf3231f96...

Client Script - Simplicity vs Efficiency

APISimplicityEfficiencyDescription
GlideRecord getReference1st5th
  • 1 L.O.C.
  • Poor UX (Blocks Browser)
  • Returns entire record
GlideRecord2nd4th
  • ~5 L.O.C.
  • Poor UX (Blocks Browser)
  • Returns entire record
GlideRecord getReference w/ callback3rd3rd
  • 5-10 L.O.C.
  • Best UX (Does not block browser)
  • Returns entire record
GlideRecord w/ callback4th2nd
  • ~10 L.O.C.
  • Best UX (Does not block browser)
  • Returns entire record
GlideAjax5th1st
  • ~20+ L.O.C. (Client Script + S.I.)
  • Best UX (Does not block browser)
  • Returns only the data you need

From here, you can see the getReference with Callback gives you the best balance between simplicity and efficiency!


Did my argumentation convinced you? 🙂

Once more, thanks for your comment!

Best Regards,

Filipe Cruz