Dot walking with m2m relationship
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 03:21 AM
Hi
Is it possible to dot walk on many to many relationship?
I have created m2m relationship where in single user can be mapped to multiple locations.
Now i am querying m2m table based on user's display name and i want to get location sys_id mapped to logged in user. I am using below code snippet in script include but it does not work.
var result_value = [];
try{
var grecord = new GlideRecord('x_inmis_im_itad_m2m_locations_users');
grecord.addQuery('user', gs.getUser().getDisplayName());
grecord.query();
while(grecord.next()) {
while(grLocation1.next()) {
result_value.push(grecord.location.sys_id);
}
}
}
catch(e){
gs.error('from script include:'+e);
gs.info('error:'+e);
}
return result_value;
How can i get location sys_id's using dot walking?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 03:25 AM
Hi there,
Can you share your full code? The code mentions grLocation1, though I'm not seeing the GlideRecord for this? Or is this a mistake in your script?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 03:33 AM
Please find below code
var result_value = [];
try{
var grecord = new GlideRecord('x_inmis_im_itad_m2m_locations_users');
grecord.addQuery('user', gs.getUser().getDisplayName());
grecord.query();
while(grecord.next()) {
result_value.push(grecord.location.sys_id);
}
gs.info(' Result is'+result_value);
}
catch(e){
gs.error('from script include:'+e);
gs.info('error:'+e);
}
return result_value;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019 04:44 AM
Hi
generally, you just need to follow the tables, as the are linked.
just dot walk from table field to table field.
example:
tableA and TableB are joined with an m2m tableM2M
tableA has field KeyA and tableB has a field KeyB.
the both key fields are used in the m2m table as KeyAm2m and KeyBm2m.
now, if you open a glide record on tableA, you can NOT dotwalk to the m2m table, as there is NO reference from tableA to tableM2M. You need to open a separate GlideRecord on tableM2M first, and THEN, you can dotwalk to the tableB.
For dotwalking, you only can walk field, that are references TO other tables, but in the M2M table case, your references are defined from the m2m table, and NOT from tableA and tableB.
let me know, if that solved your issue, and mark my answer as correct and helpful, please.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 01:27 AM
Hi
I just came across the same thing once more, and now identified your issue 🙂
It seems to be "impossible" to "dot-walk" from M2M tables.
I found some information here about it:
If you scroll down the article, you can find below the green "NOTE" block, that you CANNOT Dot-walk from M2M tables.
So, until I find something new, this seems to be our situation we have to face.
Alternatively, you need to do a separate GlideRecord to access to referenced table.
Let me know, if that answers your question, and mark my answer as correct and helpful, please.
Thanks & BR
Dirk