- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 06:25 AM
Hi Every one,
Need help in below scenario to achieve,
In my Account User getting created and adding into Group 'X'.
The requirement is Based on user group membership need to populated value in Business Unit and BU column.
Note: Both BU and Group details we are pulling it from sys_user_group table only.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 10:10 AM
then do this
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", current.group);
gr.query();
if (gr.next()) {
var userRec = current.user.getRefRecord();
userRec.u_business_unit = current.group.name; //COGS is the group name here
userRec.u_bu = current.group;
userRec.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:40 AM
Keep the same script, update the BR condition as this
current.group.name == 'GLO-COGS ServiceNow SSO Users'
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 09:21 AM
both the fields on user table are of type string?
both should hold Group name?
if yes then the BR should work fine, did you debug by adding info statements?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 09:33 AM
Business Unit is String field
BU is reference field where it is pointing to sys_user_group table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 10:10 AM
then do this
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", current.group);
gr.query();
if (gr.next()) {
var userRec = current.user.getRefRecord();
userRec.u_business_unit = current.group.name; //COGS is the group name here
userRec.u_bu = current.group;
userRec.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:57 AM - edited 03-27-2025 01:02 AM
Hi @Ankur Bawiskar ,
Thanks for guidance and your code helped me to achieve my half of the requirement.
and my code as per requirement is here in below
My requirement is if user part of
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:40 AM
Keep the same script, update the BR condition as this
current.group.name == 'GLO-COGS ServiceNow SSO Users'
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader