Add users to the list in DL members

Community Alums
Not applicable

Hi All, 

 

Having a requirement, 

 

we have a DL table where we have a members and the owners fields both are list type fields in it and the data is getting into this table is via ldap sysnc. 

while sync in the ldap transform map we have a script mapping to the field. In that we are trying to use the below script but it only picking the one value of the user and adding into the members list. if the members are multiple its not updating all the members list in the table. 

 

Any suggestions on this, below is the script that we are using in the script mapping. 

*********

answer = (function transformEntry(source) {

    if (source.u_member != '') {

        var vSource = 'ldap:' + source.u_member;

        var vUser = new GlideRecord("sys_user");
        vUser.addEncodedQuery("company=d098f022db06b300e0d1b9836b961982^sys_domain=28c7f0aedbc2b300e0d1b9836b9619ab^active=true^source="+vSource);
        vUser.query();
        if (vUser.next()) {
            return vUser.getValue('sys_id');
        } else
            return ""; // return the value to be put into the target field

    }

})(source);
 
******
1 REPLY 1

Bhavya11
Kilo Patron

Hi @Community Alums ,

 

You need modify the script little bit

 

Hoping the source.u_member has comma separated value

answer = (function transformEntry(source) {

    if (source.u_member != '') {

        var vSource = 'ldap:' + source.u_member.split(',');
       for (var i = 0; i < vSource.length; i++) {
      var ldapMember=[];
        var vUser = new GlideRecord("sys_user");
       vUser.addEncodedQuery("company=d098f022db06b300e0d1b9836b961982^sys_domain=28c7f0aedbc2b300e0d1b9836b9619ab^active=true^source="+vSource[i]);
        vUser.query();
        if (vUser.next()) {
            ldapMember.push(vUser.getValue('sys_id'));
        } else
            return ""; // return the value to be put into the target field

    }
return ldapMember.join(',');
}

})(source);

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Thanks,

BK