Script repository
The script replaces values of a custom command drop-down list parameter with allowed property values from a property pattern. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.
Parameters
$propertyPatternDN- the distinguished name (DN) of the property pattern to copy allowed values from. For information on how to get the DN of a directory object, see Get the DN of a directory object.$propertyName- the name of the property the list of allowed values will be copied from.$customCommandDN- the distinguished name (DN) of the custom command whose parameter will be updated.$parameterName- the name of the custom command parameter whose allowed values will be updated. The name must include the param- prefix.
$propertyName = "Department" # TODO: modify me
$propertyPatternDN = "CN=User Pattern,CN=Builtin,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$customCommandDN = "CN=Change Department,CN=Custom Commands,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$parameterName = "param-departmentName" # TODO: modify me
# Bind to the property pattern.
$propertyPattern = $Context.BindToObjectByDN($propertyPatternDN)
# Get allowed property values.
$values = New-Object System.Collections.ArrayList
foreach ($item in $propertyPattern.Items)
{
if ($item.PropertyName -ne $propertyName)
{
continue
}
$constraints = $item.GetConstraints()
try
{
$constraint = $constraints.GetConstraint("ADM_PROPERTYCONSTRAINTCATEGORY_VALUEFORMAT")
}
catch
{
$Context.LogMessage("No allowed values are specified for the '$propertyName' property in the property pattern.", "Warning")
return
}
if ($constraint.Type -eq "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
{
# Get allowed values
$constraint.Values | %%{[void]$values.Add($_)}
}
else
{
$Context.LogMessage("No allowed values are specified for the '$propertyName' property in the property pattern.", "Warning")
return
}
}
if ($values.Count -eq 0)
{
$Context.LogMessage("No constraint is defined for the '$propertyName' property in the property pattern", "Warning")
return
}
# Get parameter
$customCommand = $Context.BindToObjectByDN($customCommandDN)
$parameters = $customCommand.Parameters
$parameter = $parameters | Where {$_.Name -eq $parameterName}
if ($NULL -eq $parameter)
{
$Context.LogMessage("Parameter '$parameterName' not found in the custom command.", "Warning")
return
}
# Update the list of allowed values.
$parameterValues = @()
foreach ($value in $values)
{
$parameterValue = $parameter.CreateValue()
$parameterValue.Value = $value
$parameterValues += $parameterValue
}
$parameter.Values = $parameterValues
$customCommand.Parameters = $parameters
$customCommand.SetInfo()
Comments 14
You must be signed in to comment.
Robert Aich
Hello,
i'd like to extend these with additional item text.
Is there any possiblity to specify an item Text connected to values,
using formated string in property pattern with delimiter character?
e.g. Item_Text#Value
If yes, how will the PS code looks like for that?
thank you in advance
R.Aich
Support
Hello Robert,
Sorry for the confusion, but we are not sure what exactly you need to achieve. Please, describe the desired behavior in all the possible details with live examples.
Robert Aich
Hello,
i want to achive to have an specific "item text" for each entry inside the custom command drop down field and use a cryptic Value (like "comp1loc1" as value, which i want to use in a connected PSScript.
Inside a custom command i can define a parameter with a drop down list behind.
For these drop down list i am able to define hard values and item text optional, directly inside the parameter configuration.
The other way i want to use is your approach with "Copy allowed property values from property pattern to custom command parameter".
The parameters which should appear in this drop down list (Custom command) should filled out of defined property patterns.
In your script you get the Propterypattern Values and build with these the drop down list, but only the values no optional item text.
e.g. property pattern.
CustomAttributeText10 ---> Constraints -> must be one of the following values only
Location1#LocCode1
Location2#LocCode2
in PS script splitting up the pattern value first part to "item text", second part "value" (custom command drop down value)
Location1 -->ItemText for drop down entry
LocCode1 --> Value behind drop down entry
Support
Hello Robert,
Thank you for the provided details. Do we understand correctly that there is a part of the value specified in the property pattern that should be used as item text in the custom command parameter? If so, what is the separator? Could you, please, send us (support@adaxes.com) a screenshot of a drop-down defined in a property pattern along with a screenshot of the parameter items with the corresponding texts?
Robert Aich
Hello,
the separator will be, in my case, the"hash character" (#) to split the value string inside the PS Script
Support
Hello Robert,
Thank you for clarifying. For us to provide you with the updated script, please, specify what should be done if a value taken from the property pattern does not have the hash character in it.
Robert Aich
Hello,
Thank you :)
In my case it will be enough to skip the entry where the hash character is missing and place a log- message about it.
Support
Hello Robert,
here is the updated script. In the script we added the $separator variable that specifies the character used to determine parameter item value and display text.
Robert Aich
Thank you,
for providing adjusted script.
works like a charm.
DRiVSSi
Hello,
I have a custom command with an edit box, text input only, the text input is then loaded via script into a pdf with %param-text%. However, when I enter ' or ^etc. in the text input, it gives an error because it is considered as code. How can this be prevented?
Thx
Support
Hello,
Most probably, you are facing errors because the value reference used in the script is not enclosed in double quotes (" character). For details, have a look at the Value references in scripts section of the following help article: https://www.adaxes.com/help/ValueReferences/#value-references-in-scripts. Alternatively, you can get the parameter value using the GetParameterValue method of the ExecuteScriptContext class. For example, the code should look like this:
AVGuys
I am trying to use this script to import a list of locations I have defined in Property Patterns > User > Office to a Custom Command I have with a Drop Down parameter.
I have Office as a property filled in Property Patterns, with the constraint "Must be one of: Site A, Site B, Site C"
Now when I run the script, I get the error:
No constraint is defined for the 'Office' Property in the property pattern.
Which is not true, it is defined, and I made sure I copied the correct DN of the User property pattern and the destination custom command.
Support
Hello,
It looks like you set the $propertyName to Office which is incorrect. There is no property with LDAP name Office (it is just a display name and will not work). If that is correct, try setting the variable to physicalDeliveryOfficeName (that is the LDAP name of the Office property).
AVGuys
Oh my.... how silly of me! I should've known this, but wrongly assumed it was reading whatever was actually displayed in the Property column instead of the actual LDAP property name. Thank you, this worked like a charm!