Get values from lookup fields

Good day,
i have 2 lookup fields - Sucursale adresate and Categorii adresati

  1. Sucursale adresate - multiple lookup choice of ofice branch, Branch1,branch2, branch3....
  2. Categorii adresati - multiple lookup choice of categories of users - Managers,Audit, AccountManager

User must select branch office (it can be some multiple select)For example Branch1,branch2
and select category of user for example - Managers, Audit
In field cat i would like to populate all Managers and Audit users from Branch1,branch2.(fd.field('cat').value=group1;group2)
I have now all security groups Active Directory, but how to make this, need help.
and where i need to setup all this groups.

Hello @ixxxl,

Do you mean that you've synchronized AD profiles with SharePoint?

If so, you can list all members of the SharePoint group using PnPjs library:

pnp.sp.web.siteGroups.getByName('Group Name').users().then(function(users){
    console.log(users)
})

@mnikitina
Yes, AD user profiles are synchronized with Sharepoint and Active Directory security groups with email enabled are synchronized with SharePoint( i can grant permissions and send email to them) in sharepoint i see only name of security group, but can't see members ,as it seen in Sharepoint group.
i tried to get extra fields from lookup, but it works only with one choice in lookup. if my lookup is multiple i can't get values - undefined
I tried your code, but have some error:



Previosly i used like this fpr SharePoint groups, to check user membership

function showHideFields() {

    // get all groups the current user belongs to
    var userId = _spPageContextInfo.userId;
    var userGroups = [];
    pnp.sp.web.siteUsers.getById(userId).groups.get()
    .then(function(groupsData){
        for (var i = 0; i < groupsData.length; i++) {
            userGroups.push(groupsData[i].Title);
        }

        //check if the user is a member of Administrators user group
        if (userGroups.indexOf('Administrators') >= 0) {
            //Enable fields
            fd.field('AdministratorFeedback').disabled = false;
            fd.field('AdministratorComment').disabled = false;
        }

        //check if the user is a member of Managers user group
        if (userGroups.indexOf('Managers') >= 0) {
            //Show grid container
            $('.manager-section').show();
        }
    });
}

@ixxxl,

Please try out this code to get all users by group name in SharePoint 2019:

sp.web.siteGroups.getByName('Group Name').users.get().then(function(users){
    console.log(users)
})

That works on my tenant.

@mnikitina
Hi, I tried as you write and in fd.spRendered .but i have an error

@mnikitina
It doesn't work....

@ixxxl,

Please make sure that you are using a valid group name in the pnp request. You can get all available group names using teh code:

sp.web.siteGroups().then(function(groups){
    groups.forEach(function(group){
        console.log(group.Title);
    });
});
1 Like

@mnikitina
i changed to

pnp.sp.web.siteGroups.get().then(function(groups){

and now works. thanks. but i can't see active directory security groups.only sharepoint. i will try to find workaround.