- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 02:50 PM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 03:02 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 02:59 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 03:02 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 03:15 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 04:08 PM
Hello
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
API | Simplicity | Efficiency | Description |
---|---|---|---|
GlideRecord getReference | 1st | 5th |
|
GlideRecord | 2nd | 4th |
|
GlideRecord getReference w/ callback | 3rd | 3rd |
|
GlideRecord w/ callback | 4th | 2nd |
|
GlideAjax | 5th | 1st |
|
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