- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 03:01 AM
Hi Team,
I would really appreciate your help/guidance, I cannot work this out.
How can I configure a Business Rule or Client Script so that it populates a custom field I have created, with the Group/Group Names, that the currently logged in/opened by User belongs to, in the Incident form.
Custom Field is called: Created by Team (u_created_by_team) - this is where I want the User's Group Name or Names to populate to.
Source: Incident Form
Opened By field = Logged in User
I would like the Groups that the logged in user belongs to, to populate (onLoad) to the custom field (u_created_by_team), which I have set up as a sting field.
I assume this can be done by Business Rule or onLoad Client script but not sure how to do it.
Thanks ever so much - I have attached a screenshot showing my Incident Form with the fields on.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 03:12 AM
you can use display business rule on incident table and set the value
(function executeRule(current, previous /*null when async*/) {
if(current.isNewRecord()){
var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
var arr = [];
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", "IN", groups);
gr.query();
while (gr.next()) {
arr.push(gr.getDisplayValue());
}
current.u_created_by_team = arr.toString();
}
})(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
04-20-2023 03:09 AM
What would be the case if user is the part of multiple groups?
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 03:12 AM
you can use display business rule on incident table and set the value
(function executeRule(current, previous /*null when async*/) {
if(current.isNewRecord()){
var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
var arr = [];
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id", "IN", groups);
gr.query();
while (gr.next()) {
arr.push(gr.getDisplayValue());
}
current.u_created_by_team = arr.toString();
}
})(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
04-20-2023 03:22 AM
Hello Ankur,
This is brilliant ! Works perfectly, I have set it up now and all working great.
Thank you ever so much, I really appreciate your help and such a quick response.
I am very grateful for this community - thank you for your guidance.
Kind Regards, Warwick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 04:10 AM
Glad to help.
Happy learning.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader