- 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 06:30 AM
you can use after insert business rule on sys_user_grmember table which holds User<->Group membership
1) get the BU details from field present on sys_user_group and then query User and set it
something like 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.buField = gr.buFieldFromGroup;
userRec.businessUnitField = gr.businessUnitFieldFromGroup;
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-26-2025 07:07 AM
Hi @Ankur Bawiskar ,
it is not populating value in respective fields.
Here is the script which i created as per your suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 07:44 AM
your script is wrong, use 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 = 'COGS'; //COGS is the group name here
userRec.u_bu = 'COGS';
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-26-2025 08:36 AM - edited 03-26-2025 08:37 AM
Sorry to trouble @Ankur Bawiskar , Did same but no luck, it is not populating Value in Business Unit and BU.
If group is selected/added manually as GLO-COGS ServiceNow SSO USERS or added automatically by system in user profile then we need to set value of BU is COGS.