Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to remove Group Managers from Group automatically if we have a catalog item

Kaustubh k
Tera Expert

Hi Team,

We have a requirement to remove the Group managers from Groups in group table.

We have a catalog item,where we have a field Remove Manager .So whenever the user selects any manager who needs to be removed ,it should be removed from the group table as well.How can we achieve this.

 

Kaustubhk_0-1729674958700.png

Groups table:

Kaustubhk_1-1729676097682.png

Thanks in Advance

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @Kaustubh k ,

 

You can use below script to remove the selected manager from the filed.

var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('name=Help Desk');
gr.query();
if (gr.next()) {
    var inputString = gr.u_group_manager; // Replace with your actual field
    var valueToRemove = 'fe82abf03710200044e0bfc8bcbe5d18,d64b9bd783095210a9589780deaad3c6'; // The value you want to remove
    var remv = valueToRemove.split(',');
    var array = inputString.split(',');

    
    for (var i = 0; i < remv.length; i++) {
        var valueToRemoveTemp = remv[i];
		
        // Filter out the value to remove
        var filteredArray = array.filter(function(item) {
            return item.trim() !== valueToRemoveTemp.trim();
        });

        // Join the array back into a string
        var updatedString = filteredArray.join(',');
		
		array=filteredArray;
        
    }
    // Split the string into an array

gs.print(array);





}

 

You can use business rule to write the above code. I have tested it in background script, its working.

You just need to set "array" to your "u_group_manager" field.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.

Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

View solution in original post

Here in this Video, I have covered the Classifier and Process Classifier for Application Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to consistently deliver ...
1 REPLY 1

Runjay Patel
Giga Sage

Hi @Kaustubh k ,

 

You can use below script to remove the selected manager from the filed.

var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('name=Help Desk');
gr.query();
if (gr.next()) {
    var inputString = gr.u_group_manager; // Replace with your actual field
    var valueToRemove = 'fe82abf03710200044e0bfc8bcbe5d18,d64b9bd783095210a9589780deaad3c6'; // The value you want to remove
    var remv = valueToRemove.split(',');
    var array = inputString.split(',');

    
    for (var i = 0; i < remv.length; i++) {
        var valueToRemoveTemp = remv[i];
		
        // Filter out the value to remove
        var filteredArray = array.filter(function(item) {
            return item.trim() !== valueToRemoveTemp.trim();
        });

        // Join the array back into a string
        var updatedString = filteredArray.join(',');
		
		array=filteredArray;
        
    }
    // Split the string into an array

gs.print(array);





}

 

You can use business rule to write the above code. I have tested it in background script, its working.

You just need to set "array" to your "u_group_manager" field.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.

Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

Here in this Video, I have covered the Classifier and Process Classifier for Application Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to consistently deliver ...