- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2023 09:15 AM
When you parse Name Value Pairs, does it come out as a String?
sys_created_on: string = sys_created_on
sys_created_by: string = sys_created_by
parent: string = parent
parent.u_ci_unique_id: string = parent.u_ci_unique_id
parent.sys_class_name: string = parent.sys_class_name
u_number_of_relationships: string = u_number_of_relationships
type: string = type
child: string = child
child.u_ci_unique_id: string = child.u_ci_unique_id
child.sys_class_name: string = child.sys_class_name
I think parent.u_ci_unique_id is treated as a literal string which is failing dotwalking.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2023 10:30 PM
Perhaps another split and for loop will help you in that case.
For example I've simply added a "fieldList" variable that hold a comma separated list of variables and I've then turned it into an array with split(",")
Then inside the for loop for it we just need to add the previous code and change fieldNames to equal fieldList[x] so that it would basically work exactly like before.
var gr = new GlideRecord('incident');
gr.get("27a3cd6421f411004f8b9558edc753a0");
var fieldList = "assigned_to.name,assigned_to.location".split(",");
for(var x in fieldList){
var fieldNames = fieldList[x];
fieldNames = fieldNames.split(".");
var value = gr;
for (var i in fieldNames){
var fieldName = fieldNames[i];
if(value.getElement(fieldName) == 'reference'){
var refValue = value.getRefRecord(fieldName);
if(refValue){
value = refValue;
}else{
value = value[fieldName];
}
}else{
value = value[fieldName];
}
}
gs.info(value);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2023 10:30 PM
Perhaps another split and for loop will help you in that case.
For example I've simply added a "fieldList" variable that hold a comma separated list of variables and I've then turned it into an array with split(",")
Then inside the for loop for it we just need to add the previous code and change fieldNames to equal fieldList[x] so that it would basically work exactly like before.
var gr = new GlideRecord('incident');
gr.get("27a3cd6421f411004f8b9558edc753a0");
var fieldList = "assigned_to.name,assigned_to.location".split(",");
for(var x in fieldList){
var fieldNames = fieldList[x];
fieldNames = fieldNames.split(".");
var value = gr;
for (var i in fieldNames){
var fieldName = fieldNames[i];
if(value.getElement(fieldName) == 'reference'){
var refValue = value.getRefRecord(fieldName);
if(refValue){
value = refValue;
}else{
value = value[fieldName];
}
}else{
value = value[fieldName];
}
}
gs.info(value);
}