The CreatorCon Call for Content is officially open! Get started here.

What purpose does the sys_m2m table actually serve?

Stephen W_
Giga Guru

I understand it is used to create many to many relationships..

However, the first step for creating a m2m relationship, is to create an intermediary table.

I've created a table which has only two distinct fields, just location1 and location2 reference fields.

I've added the related object(red items in the slushbucket) to the form.   I've also added the related list to the bottom of the form.

I can add locations to a location using this related object form to associate the locations.

I haven't done anything with the sys_m2m table yet, because I fail to see what value it adds.

Can anyone enlighten me?

Thanks

1 ACCEPTED SOLUTION

tltoulson
Kilo Sage

Hi Steve,



First and foremost, in the wiki article Creating a Many-to-Many Relationship - ServiceNow Wiki, ServiceNow clearly states that for new Many to Many relationships you should always use the M2M Definitions table.   I would not take that lightly.   ServiceNow could be doing any number of things under the hood with Glide Objects or DB Objects for any number of reasons.   The point is we don't really know but we do know that ServiceNow supports M2M relationships via the M2M Definitions table.



On a more practical note, the M2M relationship definition method creates a related list that by default uses the "Edit" button slush bucket.   In most cases, the preferred behavior on a many to many relationship is to select from a slush bucket rather than create new records.



So yes, you can create a table that references two tables but that isn't truly a M2M relationship in ServiceNow terms.   To create a ServiceNow M2M relationship, use the sys_m2m table.



I hope this helps!


View solution in original post

13 REPLIES 13

PriyankaC
Kilo Expert

Up to date Servicenow Documentation: Create a many-to-many relationship (servicenow.com)

There is a concrete reason why you don't want to create custom tables: It counts against your custom table license.

 

 

I want you to consider a few things.

1)  The "custom table licenses" are only on certain age/class of ServiceNow contracts

1b)  The "custom table" cost factor is after a threshold, not at the margin.

2)  That "custom tables count" isn't a negative.  It is *ONLY* a net negative if the feature doesn't provide value in excess of the increased.

3)  The fear of having custom tables "count" is predicated in a complete misunderstanding of platform value.

4)  There are TWO kinds of m2m table, and the manually created (custom) kind are absolutely necessary if the relationship itself has properties beyond the two references.

On your point #4, couldn't you then just pull up the newly created Table (sys_db_object) record that was created via sys_m2m route and then add new fields from there? Not saying you're wrong here, just curious on your reasoning.

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

No, because depending on how the m2m is built it behaves quite differently in the interface.
I made a video on it.