How to add group to group list based on assignment group without effecting a group list values??

KM SN
Tera Expert

In incident I am trying to add a group called database to group list if incident assignment group is hardware and if i change assignment group from hardware to another group I need to remove the added group i.e. database from group list field without effecting the values if any  there in the group list field. 

I tried but no clue ? I tried with below code in before BR but not working as expected.

 

    var arr = current.getDisplayValue("group_list");

    var aGroup = current.getDisplayValue("assignment_group");

    var pGroup = previous.getDisplayValue("assignment_group");

    gs.log("coming arr value: " + arr + aGroup);

   

    if(aGroup.includes('8a5055c9c61122780043563ef53438e3')){//hardware

    if (arr.includes('287ee6fea9fe198100ada7950d0b1b73')) {//database

       return;

    } else {

        arr +=','+'287ee6fea9fe198100ada7950d0b1b73';

        gs.log('coming to else loop '+arr);

    }

    }else if(pGroup.includes('8a5055c9c61122780043563ef53438e3')){

        if(arr.includes('287ee6fea9fe198100ada7950d0b1b73')){

        arr-='287ee6fea9fe198100ada7950d0b1b73';

        gs.log('coming to else if loop: '+arr);

        }

    }

    current.group_list = arr;

1 REPLY 1

Rajesh Chopade1
Mega Sage

Hi @KM SN 

please try following script once and let me know, its working or not:

// Retrieve the current and previous assignment groups
var currentAssignmentGroup = current.assignment_group;
var previousAssignmentGroup = previous.assignment_group;

// Group IDs (replace these with the actual sys_ids)
var hardwareGroupID = '8a5055c9c61122780043563ef53438e3'; // Hardware Group
var databaseGroupID = '287ee6fea9fe198100ada7950d0b1b73'; // Database Group

// Get the current value of the group_list field
var groupList = current.group_list;

// Check if the current assignment group is hardware
if (currentAssignmentGroup == hardwareGroupID) {
    // If it's hardware, add the Database group if it's not already in the list
    if (!groupList.includes(databaseGroupID)) {
        // Add Database group to the group list
        if (groupList) {
            groupList += ',' + databaseGroupID;
        } else {
            groupList = databaseGroupID; // If groupList is empty
        }
    }
} else if (previousAssignmentGroup == hardwareGroupID) {
    // If the previous assignment group was hardware, remove the Database group
    if (groupList && groupList.includes(databaseGroupID)) {
        var groups = groupList.split(',');
        var updatedGroups = groups.filter(function(group) {
            return group != databaseGroupID; // Remove Database group
        });
        groupList = updatedGroups.join(','); // Reconstruct the group list
    }
}

// Set the modified group_list back to the current record
current.group_list = groupList;

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh