Getting Values from GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 01:48 PM
I'm fairly new to Jelly and the ServiceNow platform in general. I'm trying to build a UI Page and I have the shell of my HTML built but I'm having some trouble accessing the values in the GlideRecord. I have this code in place:
<g:evaluate var="jvar_cmg_io" object="true" jelly="true">
var io = new GlideRecord('x_cmgrs_digital_io_intake');
io.addQuery('status', 'Open');
io.addQuery('number', 'ORD0002455');
io.query();
</g:evaluate>
Then, later when I try to output the Order Number for instance, I'm not getting any output.
<strong>Order Number:</strong> ${ jvar_cmg_io.number }
Any help would be much appreciated. Thanks.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 01:19 PM
I do see it working in your dev instance. Fuji is the latest release, correct? I don't think our instance has been updated yet. Could that be a factor?
The only way I've been able to get any data from the 'incident' table to appear in our instance is from the with the following code:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_cmg_io" object="true" jelly="true">
var inc = new GlideRecord('incident');
inc.addQuery('active', 'true');
inc.query();
inc;
</g:evaluate>
<j:while test="${inc.next()}">
<p style="text-align: left; font-size: 20px;"><strong>Test 1:</strong> ${inc.caller_id.name}</p>
</j:while>
<j:while test="${jvar_cmg_io.next()}">
<p>Test 2:<strong> ${HTML:jvar_cmg_io.getValue('number')}</strong></p>
</j:while>
</j:jelly>
"Test 1" - dot-walking the 'inc' GlideRecod variable produces names of active users
"Test 2" - invoking the 'getValue' function on the 'jvar_cmg_io' variable produces no output, so it appears the 'while next' is evaluating to false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 02:11 PM
Okay, I think I'm making some progress. I was able to get the following to work querying the 'x_cmgrs_digital_io_intake' table:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_cmg_io" object="true" jelly="true">
var io = new GlideRecord('x_cmgrs_digital_io_intake');
io.addQuery('active', 'true');
io.query();
io;
</g:evaluate>
<j:while test="${io.next()}">
<p>Order Number:<strong> ${io.number}</strong></p>
</j:while>
</j:jelly>
So, this "while" loop gives me all the Order Numbers with an "Active" status. Eventually this UI Page is going to be linked from the main IO and display information from the current form. How would I query to only pull info for 'this' record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 02:17 PM
Hi Ryan,
There's two things to check: your use of variables, the cross-scope access policy of your table.
Test1 in your code will run the GlideRecord result set to the end. Since the variables "inc" and "jvar_cmg_io" are referring to the same GlideRecord result set, jvar_cmg_io.next() will be false because inc.next() has already moved the pointer to the end.
The whole Jelly variable vs Javascript variable thing can be confusing. I strongly recommend taking a look at SlightlyLoony's blogs about the subject, particularly this one: Jelly: Some Variables are More Equal than Others...
You can use either the Jelly variable, or the Javascript variable. Don't use both, because you might get confused as to what is happening.
So, taking the example above, remove the first or the second while loop. Once you know that you can get Incident data to output correctly, swap the table being read in the GlideRecord query to your scoped table (x_cmgrs_digital_io_intake). If your scoped table doesn't have a Number field, make sure you are trying to get the value from a field that *does* exist.
Also, make sure your UI Page is in the same scope as that scoped table, or that the table is marked as accessible to other app scopes.
Application Access Settings - ServiceNow Wiki
If, for instance, your UI Page is in the Global scope, then your x_cmgrs_digital_io_intake table must have the "Can read" checkbox marked on the "Application Access" section of the table definition. Otherwise read requests will be denied due to the cross-scope protection mechanism.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 03:09 PM
'x_cmgrs_digital_io_intake' is an unusual table name. Usually custom tables are 'u_' not 'x_' by default.
Also, are you sure there are any records in there?
If you have access to Support View then type 'tables' in the filter. Click the Tables module then filter the list of tables by name contains 'cmgrs_digital_io_intake' or similar. Assuming a table is returned click the label link. Scroll down to 'Related Links' and click Show List.
This should return a list of all the records in your table. Apply your Number is ORD0002455 filter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 03:29 PM
I verified that the table exists and contains multiple records, including the one I had originally hard-coded. Never hurts to double-check. I appreciate the assistance.