Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to dot walk a reference type list field

samarasinghe
Kilo Contributor

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.

find_real_file.png

 

 

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.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@samarasinghe 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Harish KM
Kilo Patron
Kilo Patron

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);

}

Regards
Harish

This didn't work since u_task is a list type.

That's why I tried 'u_task[1].number'

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(','));

Regards
Harish

asifnoor
Kilo Patron

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.