- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 08:25 AM
I was hoping to use the GlideRecord function "getValue()" to retrieve the value of a dot-walked field but it appears I cannot. The "addQuery()" function allows you to specify a dot-walked field so I was hoping the same would be true for getValue().
Is this intentional and if so, why?
Here's the code example to demonstrate the point. I've included the script include TyTest that has two functions, test1() which uses the getValue() and does not work and test2() which does an addQuery() and does work.
var TyTest = Class.create(); TyTest.prototype = { initialize: function() { }, test1: function () { var gr = new GlideRecord('pm_portfolio_risk'); var group = new GlideRecord('sys_user_group'); if (group.get(gr.getValue('pm_portfolio_project.assignment_group'))) { gs.log('successfully retrieved group from a dot-walked getValue() call.'); } else { gs.log('failed to retrieved group from a dot-walked getValue() call.'); } }, test2: function () { // find a project risk whose project assignment group is Chat Support var gr = new GlideRecord('pm_portfolio_risk'); gr.addQuery('pm_portfolio_project.assignment_group','e681ea120a0007dc5aba18ffb6b3e829'); // Chat Support gr.query(); if (gr.next()) { gs.log('successfully found a group by dot-walking a value in an addQuery() call.'); } else { gs.log('failed to find a group by dot-walking a value in an addQuery() call.'); } }, type: 'TyTest' };
results from running new TyTest().test1() --
*** Script: failed to retrieved group from a dot-walked getValue() call.
results from running new TyTest().test2() --
*** Script: successfully found a group by dot-walking a value in an addQuery() call.
The reason I need to use getValue() is because, unlike my TyTest example, I do not know the field I am trying to get the group value from at coding time...it's dynamic and will be determined at run-time. So, at run time, I need to look into a table to figure out what field has the field that tells me which assignment group to look for and in this case, the value returned at run-time is a dot-walked value (i.e. 'pm_portfolio_project.assignment_group' --- from the pm_portfolio_risk table). So, what I was trying to do was something like this:
if (group.get(gr.getValue(field_having_assignment_group))) {
// do work on the group
}
else {
// could not find the group.
}
I used my TyTest() script include to demonstrate this problem. Does anyone have a suggestion as to how to best solve this?
Here's a snippet of the actual code to help put it all in context for you:
var group = new GlideRecord('sys_user_group'); var map = new GlideRecord('u_map'); map.addEncodedQuery('sys_updated_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)'); map.query(); while (map.next()) { if (map.u_assignment_group == 'none') { gs.log(map.u_table + '.'+map.u_assignment_group+' is not a valid assignment_group field...skipping'); continue; } var gr = new GlideRecord(map.u_table); // u_table says what table we need to get. gr.query(); while (gr.next()) { // map.u_assignment_group will have what field within u_table will have the "assignment_group" value to use for determining the group if (group.get(gr.getValue(map.u_assignment_group))) {
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2014 08:36 AM
I've just discovered the answer to this problem: use getElement() and getElementValue(). The getElementValue() DOES allow you to specify a dot-walk string value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 09:18 AM
I want to say that you have to separate the two...
Like,
var project = gr.getValue('pm_portfolio_project');
group.get(project.assignment_group);
Or something like that. At a previous job, we had to do this when casting down a default contract that resided on the company table to the task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 10:30 AM
thanks Mike. I was thinking that, but in order to handle a dot-walk value <N> deep, that could get tricky. for example. Suppose my map.assignment_group value was something like this: "top_ref_field.ref_fiel2.final_ref_field". Here i have dot-walked over three tables. If I cannot take the full string and have Service Now handle the dot-walking, I will need to at each level of the dot-walk, determine the table for that field, open a Glide Record then get the value for that field...sort-of manually walking through the dot-walk value string. Ugh...but it's looking like that may be the case.
I'm holding out a bit longer in hopes of hearing of an alternative solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 10:35 AM
Hi Ty,
As others have said, you haven't added a query to gr yet. You may want to change your logic and separate this out more.
Thanks,
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2014 08:36 AM
I've just discovered the answer to this problem: use getElement() and getElementValue(). The getElementValue() DOES allow you to specify a dot-walk string value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2014 01:05 PM
Glad to see you have solved this. I also remember now that by using the getElement(), you don't have to query first.