- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:17 AM
Hi,
How to dot walk through list type reference field.
I have table called escalation. so, there's field called task that's List type field reference to task table.
So, I have to query as below.
ticket_number='INC9876234';
var gr = new GlideRecord('u_escalation');
gr .addQuery('u_task[1].number', ticket_number); //ticket_number means INC/SCTASK/RITM/REQ number
gr .query();
if(!gr.hasNext())
{
}
This is not working. Appreciate any guidance on this, how to dot walk this kind of list type reference field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 01:38 AM
Hi,
Only reference fields are supporting dot walk
List field don't support.
You need to query and that's the only way
1) get the sys_id of the incident you want to search and then use this query
It would look like this and will work fine
var ticket_number = 'INC9876234';
var incRec = new GlideRecord('incident');
if(incRec.get('number', ticket_number)){
var gr = new GlideRecord('u_escalation');
gr.addQuery('u_task', 'IN', incRec.getUniqueValue());
gr.query();
if(!gr.hasNext())
{
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:19 AM
var ticket_number='INC9876234';
var gr = new GlideRecord('u_escalation');
gr.addQuery('u_task.number', ticket_number); //ticket_number means INC/SCTASK/RITM/REQ number
gr.query();
if(gr.next())
{
gs.info(gr.u_task.number);
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:21 AM
This didn't work since u_task is a list type.
That's why I tried 'u_task[1].number'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:25 AM
then try this way
var list1 = current.list_field1.toString().split(',');
var list2 = [];
// Go through each sys_id found
for (var i = 0; i < list1.length; i++) {
// Get the record
var rec = new GlideRecord('table1');
if (rec.get(list1[i])) {
// Save the sys_id value from the other field
list2.push(rec.getValue('some_other_field_sys_id_value'));
}
}
// Build the list field sys_id values from the array
gs.info(list2.join(','));
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:20 AM
Hi,
What is u_task[1]. If u_task is ref list field, then you can dot walk like this u_task.number
gr.addQuery('u_task.number', ticket_number);
Mark the comment as a correct answer and helpful if this has solved the problem.
