How to populate a field on the the sys_user_group based on another field in the sys_user_grou via BR

Daniel R2
Kilo Sage

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. 

1 ACCEPTED SOLUTION

priyasunku
Kilo Sage

Hi @Daniel R2 

 

You can try below Before Business Rule 
    
var Name = current.name;    
    var Name_length = Name.toString().length;
        
    if(Name.contains('ABC-Random_ABCD-ServiceNow_AB_'));
    {
        var display_name = Name.substring(30,Name_length);
        current.u_display_name=display_name;
    }
    else
 current.u_display_name=Name;
 
Please let me know if this helpful.

View solution in original post

17 REPLIES 17

Hello @Daniel R2 

 

As in the user table, we have the first name and last name concatenated into the name field, are you asking the reverse in this question?

@prithatcs - thanks for your response, yes you could put it like that exactly.

So if sys_user_group 'name' is ABC-Random_ABCD-ServiceNow_AB_batch1

then the 'display name' should be populated with just 'batch1'

Lakshmi priya3
Tera Contributor

Hi Daniel,

 

You can writing  below code in Before Business Rule

    
var Name = current.name;
   var Name_length = name1.toString().length;     
    if(Name.contains('ABC-Random_ABCD-ServiceNow_AB_'));
    {
    var display_name = Name.substring(30,Name_length);
        current.u_display_name=display_name;
    }
else
current.u_display_name=Name;
 
Please let me know if this helpful

@Lakshmi priya3 - 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 all automatically, instead of going through each one updating them manually?

Lakshmi priya3
Tera Contributor

Hi @Daniel R2 ,

 

You can try below Before Business Rule 
    
var Name = current.name;    
    var Name_length = Name.toString().length;
        
    if(Name.contains('ABC-Random_ABCD-ServiceNow_AB_'));
    {
        var display_name = Name.substring(30,Name_length);
        current.u_display_name=display_name;
    }
    else
 current.u_display_name=Name;
 
Please let me know if this helpful.