How to add a user to company from business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 02:34 PM
Hi SNOW Community,
I have a requirement to add a Companies related list tab to the footer of the user profile form.
During the build process, I created a "many 2 many' relationship to point the companies that a current signed in user belongs too.
However, although I can get the company or companies to show in the related list view, when I visit the company profile view, no user(s) are shown to be added.
During my attempts to resolve this issue, I have tried to implement a Business Rule, but I'm not sure if the syntax I'm using is right.
I'd really appreciate any advice from the community on how best to get this feature to work.
Table: u_m2m_users_companies
var company = new GlideRecord('core_company');
company.addQuery('user_name', current.sys_id);
company.query();
while (company.next()) {
company.initialize();
company.user_name = current.user_name;
company.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 02:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 06:40 PM
Hi Seneca,
Instead of creating a business rule, how about creating a "Insert callback" on the relationship record?
addMTOM();
function addMTOM() {
var company_id = current.sys_id;
var user_id = parent.sys_id;
var company = new GlideRecord('u_m2m_users_companies');
company.initialize();
company.company = company_id;
company.user_name = user_id;
company.insert();
}
FYI:
Insert Callback | Type a script to run after a successful insert action. This field is only visible with the Advanced check box selected. |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 06:44 PM