- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 05:10 PM
I am loading the grandchild record's form. SN populates the Parent Key automatically, but I want a field that is the grandparent key (the key of the parent of the parent record). I tried using the GlideRecord but I can't get it to work. I compared my code the examples I found in the ServiceNow reference page on GlideRecord, but I am doing something wrong. I just can't see what it is.
p.s. the first part of the onLoad works fine (it hides or shows fields based on the value of Route Type). It is the second part that doesn't work.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2020 10:51 PM
My bad on point 1. Variable should have been "sysparm_step_id"
On point 2, gr.get(<sys_id>) will get a record with sys_id equal to the argument.
If using query(), use gr.next().
var GetGrandParentKey = Class.create();
GetGrandParentKey.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKey: function() {
var sysparm_step_id = this.getParameter('sysparm_step_id');
var gr = new GlideRecord('x_525091_it_sw_enh_process_model_step');
if (gr.get(sysparm_step_id)) {
return gr.process;
}
return '';
},
type: 'GetGrandParentKey'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2020 10:45 PM
Changed if condition.
var GetProcessKey = Class.create();
GetProcessKey.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getKey: function() {
var step_id = this.getParameter('sysparm_step_id');
var gr = new GlideRecord('x_525091_it_sw_enh_process_model_step');
gr.addQuery('sys_id', step_id);
gr.query();
if (gr.next()) {
return gr.process;
}
return '';
},
type: 'GetProcessKey'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2020 10:47 PM
Or
var GetProcessKey = Class.create();
GetProcessKey.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getKey: function() {
var step_id = this.getParameter('sysparm_step_id');
var gr = new GlideRecord('x_525091_it_sw_enh_process_model_step');
if (gr.get(step_id)) {
return gr.process;
}
return '';
},
type: 'GetProcessKey'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2020 10:51 PM
My bad on point 1. Variable should have been "sysparm_step_id"
On point 2, gr.get(<sys_id>) will get a record with sys_id equal to the argument.
If using query(), use gr.next().
var GetGrandParentKey = Class.create();
GetGrandParentKey.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKey: function() {
var sysparm_step_id = this.getParameter('sysparm_step_id');
var gr = new GlideRecord('x_525091_it_sw_enh_process_model_step');
if (gr.get(sysparm_step_id)) {
return gr.process;
}
return '';
},
type: 'GetGrandParentKey'
});