- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
07-17-2024 02:00 AM - edited 07-17-2024 09:47 AM
M2M (many to many) tables are used almost everywhere in the platform. Basically any table which has two reference fields to link records of two different tables could be considered M2M.
But, if you use the OOTB functionality to create M2M you will achieve that the table is recognized by the system as M2M -> when you add it to a related list the "Edit" button appears (this behaviour can be configured in "List Control"). Also, a nice side effect, this table is not counted against the number of custom tables you are licensed for. This information can be found in the "ServiceNow Custom Table Guide" under "Exempt Tables" - see attached PDF from May 2024.
It is a bit tricky when creating the table, especially when it comes to the table name, the name of the attributes (the two reference fields we want) and labels. At the end we wanna follow best practice and make it easy for fellow developers to use it later on, right?
You would start by either going to the Studio "Create Application File" and select "Many to Many Definition" or go to the sys_m2m table directly in the backend and click "New".
1) Let's assume we want to link a Service Catalog Category with a Group, to configure some business logic later on. It will look like this:
2) Ideally change the technical name and also the label to something which you find useful. Please note the "plural" name of the label in the picture above
3) Now we select the second table which is Group, also here field and label are prefilled. And notice the technical table name which is suggested:
4) Also here we would like to make a few adjustments:
Now it looks useful and understandable in my opinion and we can click on "Create Many to Many". To make it perfect the last thing to do is, we go to the dictionary and adjust the label of the table we just created.
Please let me know if this article was helpful for you by using the buttons below.
- 7,713 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for this info.
What if the newly created m2m table does not appear in the related list slush bucket of either tables involved in creating this m2m table?
Thanks