- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 12:02 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:54 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:22 AM
Y-Developer,
ServiceNow usually has multiple ways to things. Here's a fairly easy way to do what I think you're trying to do. Show a list of records related to the current record.
- Create Custom Table or Choose an Existing Table for the Related List
- Note your table name
- Secret Test
- u_test_table
- Note your table name
- Create a reference field to the user table (sys_user) on your table
- I made one called Owner
- I made one called Owner
- Go to System UI > Related Lists
- Look for the table and view you want to add your list to
- I'm going to use the sys_user table and the default view to add the list
- Scroll down to the Related List Entries Related list (not confusing at all)
- Click New
- In the Related list field put <table_name>.<reference_field_name>
- Mine is "u_test_table.u_owner'
- The new record should show in the list. At this point I used List Edit (dbl click the field) and set the Position...but you can set it when you create the record if you remember what it should be 😄
- Now you can go to a record on that table, in that view (form)
- Adjust columns as needed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 01:11 PM - edited 01-05-2023 02:30 PM
Oh, I needed to link the sys_id of the user, correct? I forgot about that because they're logging into SN using their school account (I work at a college). I wonder if that was one of the items tripping me up? @ricker I'm sorry to be thick on this topic, you're so very kind to try to help me but I feel so foolish not understanding.
Following your example is great, I did it with expected results. However, you nailed it perfectly...your tutorial activity led me what I may, truly, need - which is a one-to-many relationship. Where 1 student (1st table) has many entries (2nd table). Honestly, 2 days trying to figure out something so simple...
So if I continue this way then if I had a u_student_id in Table1 and u_table2_student_id in Table2 - could I link them together using a reference data type? If so, then when a new student is entered on Table1, then there's no 'auto creation of a record' at all happening between the 2 tables...Table2.u_table2.student_id merely 'references' Table1.u_student_id
When I tried to do that on my PDI I just get the auto-generated index number to choose from, not the student id I linked to...pic attached... how can i get the picker to show the student id instead?
Please let me know if I'm on the right track. If this is too silly-of-a-question could you point me in the direction of the SN docs?
BTW - I saw your super cool browser extensions to show technical names using SN Utils... I'm using it now too, thanks to you. Very helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 09:33 AM
Additionally, in searching out this out doc:
https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/table-adminis...
where I go wrong is that it explains that:
- In the To table field, specify a child table.The Many-to-Many form automatically populates the other fields with suggested values.
I don't know how that happens. So, I'll give a quick example to illustrate my confusion:
Table1:
u_auto_number:integer
u_client_name:string
u_client_address:string
Table 2:
u_table2_autonumber:integer
u_table2_name:string
u_table2_health_conditions:string
So, if I make a new entry in Table1, I'd like an entry to be automatically entered into Table2 with at least the name fields being copied. Is that what the m2m table does? I don't understand which fields update automatically. What am I missing in this? I must have a mind-block on this simple concept. I do thank you for helping me out, sometimes I have a hard time getting concepts - but when I finally get it, it'll be solid!
Thanks for your patience and help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:54 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 10:04 AM
@rickerThank you so much for taking the time to help me out. You answered my question. Sorry it took so long for me to get there but I believe I came away learning more about SN and how it operates. All answers built up on each other, including @Anurag Tripathi giving those links too. Thank you to both for the support. I hope you both have a great weekend.