Filter users by SPS-SourceObjectDN

I'm trying to filter the users returned in org chart by specific Azure AD OUs. This is primarily to exclude Admin and Domain Admin users from the org chart.

All users I want showing are all contained within the following subfolders of the OU "OU=Users":

OU=COMPANYNAME,DC=COMPANYNAME,DC=INT

The AD OUs are synced to SharePoint User Profiles under the 'Source Object Distinguished Name' field (field name: SPS-SourceObjectDN).

The filtration code I'm currently using is:

function(itemData){

var source=["OU=Users", "OU=COMPANYNAME", "DC=COMPANYNAME", "DC=INT"];
return source.includes(itemData["SPS-SourceObjectDN"]);
}

What am I doing wrong? I am by no means a competent coder, so idiot-proof responses only, please :slight_smile:

Hello Alex! I assume that the content of the "SPS-SourceObjectDN" field does not match with the strings you specified in the "source" array. To check it, please replace your code with the following:

function(itemData){

  console.log(itemData["AccountName"]);
  console.log(itemData["SPS-SourceObjectDN"]);

  return true;
}

Save the changes, press F12 to open the browser devtools, switch to the "Console" tab and reload the page. After reloading the page, you should find there records with the account names and accordant values of the "SPS-SourceObjectDN" field. Thus, you will see how the data are present for Org Chart and be able to modify your code if required. If you will still experience difficulties with that, please save all the console logs (context menu of any record > save as) and share them with me through a private message in the community or raise a new ticket by sending a message to [email protected]. In the last case, please refer to this topic so that the ticket would get to me.

Hi Evgeniy,

Thanks for your reply and for your suggestion to check the user record data.

It turns out that the "SPS-SourceObjectDN" field isn't correctly populating with data from AD, which is why the source array isn't matching. I tried it with "SPS-DistinguishedName" and it returned data just fine.

So it looks like I'll have to review how AD is syncing with SP user profiles. At least I know what the problem is and that my function will work once that data is there.

Many thanks,

Alex

1 Like