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 (140 points)

1 Answer

0 votes
by (270k 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

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

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)
0 votes
1 answer

Hi, I followed this example: https://www.adaxes.com/sdk/IAdmTop6.html, but because the Custom Command is disabled, I get the following error message: System.Management.Automation ... if I enable the Custom Command. I am using Adaxes 2018.2 Best Regards Martin

asked Feb 19, 2020 by Martin (100 points)
0 votes
1 answer

I'd like to be able to either send an email report or export a CSV of all of the business rules carried out when a user is disabled. This would be ... Management Activity section but this includes things that weren't part of the disable operation. Thanks

asked Feb 19, 2020 by bavery (250 points)
3,326 questions
3,026 answers
7,727 comments
544,681 users