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

M2M question - super noob question

Y-Developer
Tera Contributor

Hi Everyone,

I've been doing full stack dev for years but as I dive into ServiceNow there are so many things that happen 'under the hood' that it sometimes eludes me as to what to do.  I am sorry if I don't get this immediately but I have a super simple project where there is an initial form (initial_form) to allow people to enter their demographic information (name, address, etc.).  After the client fills in the form and submits it, I want to automatically create a separate record in another table (full_details_form) that will have further, more detailed fields (eg. medical history) which will be viewable by the owner only.

So, I thought I'd use the m2m list to help manage that auto-magically.  Meaning, the client enters their info on the initial_form, SN automatically creates a record in the full_details_form and links it all nicely in the m2m table.  Also, if the client wants to edit some allowable information in their record, will m2m automatically update any references?  I'm so confused and I've scoured videos and the SN docs.  I'm sorry if this is obvious...

I honestly don't understand how m2m works if it's supposed to help or what it does - perhaps I'm missing just a simple piece of information.  In my old work I'd have to create the associative table and use server-side scripting to manage the PK and FK of it all. 

Could someone please point me in the right direction...am I asking the right question?  should I be using m2m at all?  what are the magic advantages it has?

Thank you for your time and help in advance.

1 ACCEPTED SOLUTION

Y-Developer,

I think you might be combining a couple things.  An M2M relationship links things like a Group to multiple users and a User to multiple Groups.  When you add a user to a group there is a record created on the M2M table "sys_user_grmember" but creating a User or Group does not automatically create a User or Group record.  the sys_m2m record creates a new M2M table for your relationship similar to "sys_user_grmember" table.  If you look at the sys_collection table

plug your instance name in link below to go to sys_collection table filtered to sys_user_grmember table.

The sys_collection records are the OOB M2M relationships...It's a confusing because they use two records there but in sys_m2m the one record does the job of both sys_collection records.

 

https://<instance_name>.service-now.com/now/nav/ui/classic/params/target/sys_collection_list.do%3Fsy...

 

In order to have a 2nd record created based on the first you need some sort of automation, Flow, Workflow, Business Rule...

I just realized you might be trying to create your tables with the M2M record?....The tables you're relating need to be created before the sys_m2m record.

Hopefully that's helpful.

 

View solution in original post

10 REPLIES 10

ricker
Tera Guru

Y-Developer,

I'll try to get you going the right direction.  On your new table (full_details_form) you will need a reference field that points to the sys_user table....when you create a full details form record for a user you'll put them in that field (it's the sys_id of the user record) to relate the details back to the user.

You can create a related list with "full_details_table_name.user_field" in the Related List field.

You'll need ACLs to secure the data appropriately also.

 

 

Hi @ricker , I am truly grateful for your response.  Thank you.  I suppose I got enamored with the 'automation' portion of it all.  I'm going from 0 to 10 (not even 100 yet) on learning the intricacies of SN.  I've completed the Fundamentals course but it doesn't prepare me for all this - that's just my opinion. 

When you create the reference field, does that make an entry in the sys_m2m list?  I know I could try it but I'm wanting to know ahead of time so my mistake isn't one that can't be undone.  Also, my app is scoped and I believe I may need to rethink the initial_form's function.  I feel like I'm drowning in minor details that are paralyzing my efforts to move forward.  

I'll try your suggestion and report back today, @ricker , thanks again.  I hope your day goes well.

Hi,

check this out

Relationships in ServiceNow Explained - ServiceNow Community

the 2nd type of relationship here will create the M2M table.

-Anurag

Y-Developer,

You're welcome...first off good job on completing the Fundamentals course and don't worry about breaking your PDI :D.

No, creating the reference field does not create an M2M record.  I don't think you actually want a many to many relationship here.  You're going to want one user to one special data record or possibly one user to many special data records...right?  I'll have to make something to remember the exact steps.