- 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:08 AM
I haven't tested the getValue() using dot-walking yet, but line 10 in your post shouldn't work.
You're doing a gr.getValue(), yet have no record in the current context of gr at this point.
if (group.get(gr.getValue('pm_portfolio_project.assignment_group'))) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 10:22 AM
- var gr = new GlideRecord(map.u_table); // u_table says what table we need to get.
- gr.query();
- while (gr.next()) {
See lines 12,13,15 (above), that sets the context. map.u_table will have the name of the table (in this case 'pm_portfolio_risk'). Then continuing this example, the 'map.assignment_group' value will be 'pm_portfolio_project.assignment_group'.
That's why I provided the TyTest example in function test1() to illustrate what is happening.
In other cases, like map.u_table = 'incident', map.assignment_group = 'assignment_group', there is no problem because the map.assignment_group value does not have a dot-walked value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 10:35 AM
Oh...I think I see your point Mark (the TyTest line 10, not my actual example).
Ok, let me change that. and see
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2014 11:17 AM
No luck. I made the correction to my example code (TyTest) and the results are still the same:
test1: function () {
var gr = new GlideRecord('pm_portfolio_risk');
var group = new GlideRecord('sys_user_group');
var proj_gr = new GlideRecord('pm_project');
if (proj_gr.get('6ef2405d009c7000c8e0ba638d6d3ccf')) {
gr.pm_portfolio_project = proj_gr.sys_id;
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.');
}
}
else
gs.log('could not find the project.');
},
Result yields:
*** Script: failed to retrieved group from a dot-walked getValue() call.