Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

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

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on
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

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

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on