Generating Values based on other values in form

I have seen one good thread about this a couple of months ago demonstrating the use of the "onGetEffectivePolicy" handler, but I can't seem to get a script to work for my needs. What I want to accomplish is multi-tiered, and my script is complete and is falling down somewhere as a result.

The objective is for the admin to:

  1. Select a value from a drop down menu configured in a policy (which writes to an AD extension attribute)
  2. Populate the First Name entry ("givenName") and Last Name entry ("sn"),
  3. Have a script module read the value from the drop down selection, and based on the value:
    1. Generate a custom, appended value in the UPN and sAMAccount entries, e.g.:

Drop down selection: "Privileged account"

First Name: John

Last Name: Smith

Generated UPN: "XXX_JSmth@<domain>"

Generated sAMAccountName: "XXX_JSmith

This is far as I have gotten, (and I recognize it's pretty far from the goal):

function onGetEffectivePolicy($Request)
{
   if ($Request.Class -ne "user") {return}
        
    $AccountType = $Request.Get('<attribute>')
    $Firstname = $Request.Get('givenName')
    $LastName = $Request.Get('sn')
    $CustomVar = "XXX_"+$Firstname[0]+$LastName
    $ResponseValue = GenerateCustomVar $CustomVar
    $strAttrName = "sAMAccountName"
    
            
    if ($AccountType -eq 'Privileged account'){
    
    $Request.SetEffectivePolicyInfo($strAttrname, $Constants.EDS_EPI_UI_RELOAD_EPI_BY_RULE, "AccountType")
    $Request.SetEffectivePolicyInfo($strAttrname, $Constants.EDS_EPI_UI_AUTO_GENERATED, $strAttrname)
    $Request.SetEffectivePolicyInfo($strAttrname, $Constants.EDS_EPI_UI_GENERATED_VALUE, $ResponseValue)   
    }

    else {return}

What am I missing?

Top Replies

  • Hi  

    Instead of trying to populate a generated value ($Constants.EDS_EPI_UI_GENERATED_VALUE), instead try defining a policy rule ($Constants.EDS_EPI_UI_GENERATED_VALUE)

    In your instance something…

  • Hi  

    Instead of trying to populate a generated value ($Constants.EDS_EPI_UI_GENERATED_VALUE), instead try defining a policy rule ($Constants.EDS_EPI_UI_GENERATED_VALUE)

    In your instance something like

    function onGetEffectivePolicy($Request)
    {
        $AttributeName = "sAMAccountName"
        
        $TextPrefix = "XXX_" # Or what were value you want
        $PolicyRule = "%1<givenName>%<sn>"
        $AttributePolicyRule = [string]::Format("{0}{1}",$TextPrefix,$PolicyRule)
        $DisplayNote = "Scripted generation of $AttributeName, rule is $$AttributePolicyRule"
        
        $Request.SetEffectivePolicyInfo($AttributeName, $Constants.EDS_EPI_UI_RELOAD_EPI_BY_RULE, "AccountType")
        $Request.SetEffectivePolicyInfo($AttributeName, $Constants.EDS_EPI_UI_AUTO_GENERATED, 'any')
        $Request.SetEffectivePolicyInfo($AttributeName, $Constants.EDS_EPI_UI_DISPLAY_NOTE, $DisplayNote)
        $Request.SetEffectivePolicyInfo($AttributeName, $Constants.EDS_EPI_UI_POLICY_RULE, $AttributePolicyRule)
    }
    

    Hope this helps

    Stu