Error calling saved object properties to script from workflow

Background:  I have a workflow that triggers on the modification of an attribute on a group (it contains who owns the group).  The groups in question provide access to servers so we need to keep the owners of the computers updated with what the group owner is. The groups are named adm-<servername>.     

I can get the workflow to trigger no problem but in order to trim off the adm-, i need to use a script as there is no workflow function i can find to trim the first 4 characters off a field so i can search against it.  Below is my script call but when it tries, i get Exception calling "SavedObjectProperties" with "1" argument(s): "The given key was not present in the dictionary.". 

$groupfound = $workflow.SavedObjectProperties("Save object properties").get("cn")
$groundfound.substring(4)
return $groupfound

The "save object properties" is just a default control pointing to the Workflow Target.  The CN is on the listed properties, i can see in the history that it is saving the proper object but not passing to the script.

I've also tried 

$workflow.ActivityTarget("Workflow to update computer sponsor")

no luck with either.

  • Sorry i should of finished the workflow background.  I take the name of the group, need to remove the first 4 and get the computer name.  I then search for the computer and update the sponsor.  The issue i am having is that i can't push the target to the script so i can trim off the first 4 characters.

  • So i was able to change and use the $request and i can see in the debugging that it's pulling the values (script below).  However, when i try to use the returned value, the workflow says it's multivalued and expecting single.

    function GetComputerName($Request)
    {
    $request.guid
    $user = get-qadgroup $request.guid -includedproperties cn,samaccountname
    $sam = $user.samaccountname
    $Computer = $sam.substring(4)

    return $Computer
    }

    Debug to show values:

    DEBUG: 1+ >>>> s2ae4637b-6ff5-472c-a6e3-6329b3e2c5ca 'GetComputerName' $Request
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 24+ >>>> &$args[0] $args[1]

    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 3+ >>>> {

    DEBUG: ! CALL function 'GetComputerName'
    DEBUG: 4+ >>>> $request.guid

    DEBUG: 5+ >>>> $user = get-qadgroup $request.guid -includedproperties cn,samaccountname

    DEBUG: ! SET $user = 'ROOTFOREST\ADM-USCGM1ARSP1'.
    DEBUG: 6+ >>>> $sam = $user.samaccountname

    DEBUG: ! SET $sam = 'ADM-USCGM1ARSP1'.
    DEBUG: 7+ >>>> $Computer = $sam.substring(4)

    DEBUG: ! SET $Computer = 'USCGM1ARSP1'. <-----This is the SERVER name and is what i expect to come back
    DEBUG: 9+ return >>>> $Computer

    DEBUG: 10+ >>>> }

    Error in change history for workflow indicates it's getting multi instead of single.

    Illegal data entry. Workflow activity encountered data entry of multiple values in a situation where a single-value data entry is required. Check configuration of the workflow activity

  • How about something like this:

    Function GetComputerName ($Request)

    {

    # Grab the target object name from the $Request and parse out just the Name of the group

    # So initially, you get CN=ADM-USCGM1ARSP1 - i.e. the split...[0] bit gives you the first field of the object DN

    # Then lop off the ADM-

    $Computer = [string]$($Request.DN).split(",")[0].replace("CN=","").replace("ADM-","")

    $Computer

    }

  • NOTE:  My code assumes that your change workflow is trapping a modification to your computer's ADM group.

  • Edited my code... may not be necessary but just to be sure all the string manipulation works.