- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 12:47 AM
Hi,
On the sys_user_group form we have added a custom field called 'Display Name'
This is due to the fact that the name is to complex and we would prefer a more understandable display name.
There is a requirement to populate the custom field 'Display Name' based on the 'Name' field on the sys_user_group form through a Business Rule.
(The reason for this configuration, is due to a previous integration which has imported the necessary groups. So if more groups get loaded in the future, this Business Rule should organise it. We would also like a better dislplay name, as already mentioned above)
For e.g.
- If the "Name" field starts with "ABC-Random_ABCD-ServiceNow_AB_" it should be cut and the remaining text should be the "Display name"
- Otherwise "Name" should be copied fully to "Display name".
Is it possible if someone can please provide their support here or provide a script that would allow this to work.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 08:04 AM
Hi @Daniel R2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 08:04 AM
Hi @Daniel R2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 02:46 AM
@priyasunku - This works perfectly thank you! Before i accept the solution, i have one other question.
We have around 130 groups that need updating, what background script can we run to update these automatically, instead of going through each one updating them manually?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 02:55 AM
Hi @Daniel R2
please try below code to run in backround script
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name' 'CONTAINS' 'ABC-Random_ABCD-ServiceNow_AB_');
gr.query();
while(gr.next())
{
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 03:29 AM
Thanks again @priyasunku for the reply. I have just tested this, but it doesnt seem to be working. The records are not updating automatically
Error that we can see is: 'Unexpected Token 'CONTAINS'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 03:54 AM
please try this
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', "CONTAINS" ,"ABC-Random_ABCD-ServiceNow_AB_");
gr.query();
while(gr.next())
{
var Name = gr.name;
var Name_length = Name.toString().length;
var display_name = Name.substring(30,Name_length);
gr.u_display_name=display_name;
gr.update();
}