We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Auto Set Group resource assignee Field when Resource Assignee is set in SPM

Trupti Krishnam
Tera Contributor

I want to Auto Set Group resource assignee Field when Resource Assignee is set in SPM . I have 2 field named as Group resource assignee and Resource Assignee , whenever I assign users to Resource assignee field it should populate the Group name in the Group resource assignee . Whenever I add users belongs to same group in the resource assignee field it should populate Group name once in Group resource assignee . If I add users from different group in resource assignee it should populate the Group Resource Assignee with 2 different Group names . 

I have created a Before BR insert or Update BR 

and I have written this script but it is not working can anyone help with answer

var resource = current.resource_assignee.toString().split(',');

    var groupSysIds = [];
    var seenGroups = {};

    for (var i = 0; i < resource.length; i++) {
        var userSysId = resource[i].trim();

        if (!userSysId) {
            continue;
        }

        var empGr = new GlideRecord('sn_employee_profile');
        empGr.addQuery('user', userSysId);
        empGr.addNotNullQuery('primary_resource_group');
        empGr.query();

        if (empGr.next()) {
            var groupSysId = empGr.getValue('primary_resource_group');

            if (groupSysId && !seenGroups[groupSysId]) {
                seenGroups[groupSysId] = true;
                groupSysIds.push(groupSysId);
            }
        } else {
            g_form.showFieldMsg('group_resource_assignee', 'No Employee Profile / Primary Resource Group found for user:', 'info');
        }
    }

    current.group_resource_assignee = groupSysIds.join(',');
 
 
1 REPLY 1

Trupti Krishnam
Tera Contributor

Both the fields are list collector 

TruptiKrishnam_0-1784207293743.png