0 votes

I have a dropdown-field on the web surface, which is populated by a script. The script looks up all groups in a specific OU and displays them. In the Property Pattern all groups are displayed in alphabetical order. image.png

But on the web portal the groups are shown in a random order.

image.png

What should i do to show the groups in alphabetical order in the portal?

by (160 points)

1 Answer

0 votes
by (289k points)

Hello,

The thing is that the script adds values to the Property Pattern is the order groups are found during the search and when you open editing of the setting, it gets automatically sorted. If you refresh the Web Interface page after that, you will also see sorted values. Unfortunately, there is no possibility to change the behavior. To achieve the desired sorting, you can sort the values in the script before adding them to the Property Pattern. If you have issues updating the script, please, post it here or send to us (support[at]adaxes.com) and we will help you.

0

I'm not sure how to update the script. Thanks for your help! The following script is in a custom command which will be executed by a scheduled task every 30 min

$patternName = "Benutzer-Muster" # TODO: modify me
$propertyToUpdate = "extensionAttribute5" # TODO: modify me

function SearchObjects($filter, $containerPath)
{
    $searcher = $Context.BindToObject($containerPath)
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Get all groups in the target OU
$groupSearchResults = SearchObjects "(objectCategory=group)" $Context.TargetObject.AdsPath

# Exit if no groups found
if ($groupSearchResults.Length -eq 0)
{
    return
}

# Get group names
$groupNames = New-Object System.Collections.ArrayList
foreach ($searchResult in $groupSearchResults)
{
    $groupNames.Add($searchResult.Properties["name"].Value)
}

# Find Property Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$patternSearchResults = SearchObjects "(&(objectCategory=adm-PropertyPattern)(name=$patternName))" $propertyPatternsPath

if ($patternSearchResults.Length -gt 1)
{
    $Context.LogMessage("Found more than one Property Pattern with name '$patternName'.", "Warning")
    return
}
if ($patternSearchResults.Length -eq 0)
{
    $Context.LogMessage("Property Pattern '$patternName' does not exist.", "Error")
    return
}

# Bind to the Property Pattern
$pattern = $Context.BindToObject($patternSearchResults[0].AdsPath)

# Delete the pattern item for the property
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq $propertyToUpdate)
    {
        $pattern.Items.Remove($item)
        break
    }
}

# Create list of values for the property
$item = $pattern.Items.Create()
$item.PropertyName = $propertyToUpdate

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $groupNames.ToArray()
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Update Property Pattern
$item.SetInfo()
$pattern.Items.Add($item)
+1

Hello,

Thank you for the confirmation. Here is the updated script.

$patternName = "Benutzer-Muster" # TODO: modify me
$propertyToUpdate = "extensionAttribute5" # TODO: modify me

function SearchObjects($filter, $containerPath)
{
    $searcher = $Context.BindToObject($containerPath)
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"     

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Get all groups in the target OU
$groupSearchResults = SearchObjects "(objectCategory=group)" $Context.TargetObject.AdsPath

# Exit if no groups found
if ($groupSearchResults.Length -eq 0)
{
    return
}

# Get group names
$groupNames = New-Object System.Collections.ArrayList
foreach ($searchResult in $groupSearchResults)
{
    $groupNames.Add($searchResult.Properties["name"].Value)
}

# Find Property Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$patternSearchResults = SearchObjects "(&(objectCategory=adm-PropertyPattern)(name=$patternName))" $propertyPatternsPath

if ($patternSearchResults.Length -gt 1)
{
    $Context.LogMessage("Found more than one Property Pattern with name '$patternName'.", "Warning")
    return
}
if ($patternSearchResults.Length -eq 0)
{
    $Context.LogMessage("Property Pattern '$patternName' does not exist.", "Error")
    return
}

# Bind to the Property Pattern
$pattern = $Context.BindToObject($patternSearchResults[0].AdsPath)

# Delete the pattern item for the property
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq $propertyToUpdate)
    {
        $pattern.Items.Remove($item)
        break
    }
}

# Create list of values for the property
$item = $pattern.Items.Create()
$item.PropertyName = $propertyToUpdate

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$groupNames.Sort()
$constraint.Values = $groupNames.ToArray()
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Update Property Pattern
$item.SetInfo()
$pattern.Items.Add($item)
0

Thanks for your help, works perfect.

Related questions

0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 points)
0 votes
1 answer

In order to add a managed domain does it have to be trusted by the primary domain adaxes is installed an running in? I have set up a domain for testing adaxes and it ... I have set my host file to point the untrusted domain to it's primary Domain Controller.

asked Oct 5, 2022 by mightycabal (1.0k points)
0 votes
1 answer

I am trying to trigger processing outside of Active Directory when an account is created based on the source user account that was used. Does Adaxes store the source account anywhere?

asked Oct 9, 2023 by jnordell (20 points)
0 votes
1 answer

Is it possible to have a business rule of the form: IF (company = "Company1") then set City = "New York" set Manager = "New York Manager" If (state = "CO") then set telephone "303" else if (state = "NY") set telephone "202" else clear telephone end if end if

asked Aug 23 by Jiver (20 points)
0 votes
1 answer

I had a script that would copy the values from adm-CustomAttributeTextMultiValue1 and save them into extensionAttribute15 as a comma seperated list. The script somehow got deleted and I can't seem to find the tutorial I used to create it before.

asked Jul 1, 2022 by jordan (110 points)
3,548 questions
3,239 answers
8,232 comments
547,814 users