Social

lørdag den 8. februar 2014

Including extension properties in the description field

User input is often mapped to extension properties of Manual/Review activities. The input can be made easier to comprehend by adding labels to each:

As a service to activity implementors these properties can be included in the description field as part of a complete text (with some Orchestrator magic!). A simple example is a password reset where the line manager must approve or decline a request for a password reset. The description field could read something like

User has requested a password reset. See extension tab for further details.

The extension tab could then include a username and a reason for the request. I will now show how the description could be changed automatically to:

CB.IT has requested a password reset with the following reason: "I changed my password yesterday and now I cannot remember what it is".

The title could also be changed to:

Approve password reset - CB.IT

One approach to implementing this feature is to use Markup Language and Orchestrator. For this particular example one would first change the "password reset" template where the description field should look like this:

<CB_CstmTxt1> has requested a password reset with the following reason: <CB_CstmTxt2>.

This is a simple way of telling Orchestrator that we would like to substitute the tag <CB_CstmTxt1> with the value in the extension property named CB_CstmTxt1 (containing the username of the requesting user). CB_CstmTxt2 then contains the reason for the request. To change the title we would put

Approve password reset - <CB_CstmTxt1>

Next up is creating a monitoring activity in Orchestrator that looks for new Review Activities, and then updates them using Powershell:
The script:

Import-Module SMLets

$ID = 'RA29'
$RA = Get-SCSMObject -Class (Get-SCSMClass -Name System.workitem.Activity.ReviewActivity.extension) -Filter "DisplayName -like '$ID%'"

$PropertyNames = $RA.GetProperties() | select -ExpandProperty Name

$Title = $RA.Title
$Description = $RA.Description

foreach($P in $PropertyNames)
{
    #$P
    $Value = $null
    try {
        $Value = $RA | Select -ExpandProperty "$P"
        if($Title.Contains("<$P>"))
        {
            $Title = $Title.Replace("<$P>", "$Value")
        }
        if($Description.Contains("<$P>"))
        {
            $Description = $Description.Replace("<$P>", "$Value")
        }
    }
    catch [System.Exception] {
        # value is null
    }
}

# uncomment below to echo title and description
#"$Title, $Description"

$PropertyHash = @{"Title" = $Title; "Description" = $Description}
$RA | Set-SCSMObject -PropertyHashtable $PropertyHash

This will be modified slightly to work in a runbook. Edit the $ID variable and try it out in your own environment. For the runbook edit to filter on "ID" and compare to the GUID provided by the monitor activity.

Ingen kommentarer:

Send en kommentar

Bemærk! Kun medlemmer af denne blog kan sende kommentarer.

Søg i denne blog