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 02:31 PM
Ryan, I see there has been a lot of activity. I wanted to check in and see where you were. I was trying to figure out, but I thought I would just ask before attempting to solve anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 02:49 PM
Hi Dylan,
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, I now have 2 questions:
- 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?
- There are a couple fields on the form that reference other tables. How do I access those values? Do I need to create a separate GlideRecord?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 03:19 PM
Can you explain a little more about how you're going to use this UI page and what you mean by "main IO"?
As for your second question, I'll have to check. What other information were you going to want to display on this UI page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 03:37 PM
Basically, we have an Insertion Order (IO) form and I'm creating a UI Page that will allow our employees to display some customized reports that aren't available using ServiceNow's built-in reporting technologies. When they go to the Insertion Order (IO) and click an "Export" link, the UI Page will open. From there, it should allow them to print or export to a PDF.
There are a bunch of reference fields on the form. For example, when I right-click the "Digital Specialist Name" field, and click "show 'coordinator_name'" I get the following:
Dictionary Info: x_cmgrs_digital_io_intake.coordinator_name
Table: x_cmgrs_digital_io_intake
Element: coordinator_name
Type: reference
Reference: sys_user
I'm able to output the fields directly associated with the 'x_cmgrs_digital_io_intake' table. For example ${ io.campaign_start_date } and ${ io.campaign_end_date })
However, if I try to output ${ io.coordinator_name } I'm not getting a value and I think this has to do with the fact that it's a reference field.
Let me know if that helps clarify things. I appreciate the assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 03:49 PM
Some others may chip in, but I've done something kind of similar before.
Basically, you'll add some parameters to the url when you open the UI Page, such that the following url is formed: instance.service-now.com/ui_page.do?sysparm_parm1=text
Then, on your UI page a client script will decode this:
function getParmVal(name){
var url = top.document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
In our example, when the page was ready it would call the following function (also in the client script section):
function setPageValues() {
var parm = getParmVal('sysparm_parm1');
if(parm){
alert(parm);
}
}
In the body of the ui page:
<script>
$j('tr.sc_header').hide();
$j(document).ready(function() {
setPageValues();
});
</script>
If you want to return multiple references, maybe you want to write a script include that will return all the values you need as a JSON object perhaps?
Let me know what you think so far.