locked
SCSM 2012 R2 Custom Workflow with Powershell RRS feed

  • Question

  • Hi,

    I am working out on SCSM 2012 R2 workflow customization with SM Authoring tool. I have a Powershell script what able to set the "Support Group" according to "Incident Classification" for instance.

    The challenge is that i want this Powershell script to execute on the latest updated incident instead of execute the checking on all existing incidents.

    How should i go about this, so that I can have a workflow that only react on the latest incident?

    Thank you.

    Wednesday, December 24, 2014 7:46 AM

All replies

  • Hi Aries,

    Do you mean the incident which as the latest date of the Last Modified field?

    Maybe you disclose a bit more about the final goal?


    Cheers,
    Marat
    Site: www.scutils.com  Twitter: LinkedIn: Graveyard:

    Wednesday, December 24, 2014 12:57 PM
  • Hi,

    I am working out on SCSM 2012 R2 workflow customization with SM Authoring tool. I have a Powershell script what able to set the "Support Group" according to "Incident Classification" for instance.

    The challenge is that i want this Powershell script to execute on the latest updated incident instead of execute the checking on all existing incidents.

    How should i go about this, so that I can have a workflow that only react on the latest incident?

    Thank you.

    I guess you want the workflow to run when the incident classification changes?

    http://codebeaver.blogspot.dk/

    Thursday, December 25, 2014 8:30 AM
  • You can easily set up workflows that trigger when classes are updated, this is what you should do for the whole workflow. set up your class and criteria with the workflow.

    When you add in the powershell activity, make sure you add a script property that includes the class property "ID" (which would be the workitem id, i.e. "SR1234") or the class property "ID (Internal)" (which would be the GUID of the object, such that you could call Get-SCSMObject -id). the Name of the script property is passed as a variable name (using the Param powershell directive) into your powershell script. 

    when you save this out, it should contain a write activity that looks like this one:

                  <WriteAction ID="AutomaticActivityChangeRisk.WindowsPowerShellScript.d8af208f_45ee_4ac9_ba64_b9b5cc370e1d.PSWA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
                    <ScriptName>Change-Automation.ps1</ScriptName>
                    <ScriptBody>param ( [string]$ID )
    import-module smlets
    
    $ACClass = Get-SCSMClass System.WorkItem.Activity$
    
    #Get the AC object for this automated activity. 
    #The server side filter for System.WorkItem.Activity$ is DisplayName as the workitem ID. 
    $ThisAC = Get-scsmObject -class $ACCLass -filter "DisplayName -eq $ID"
    
    #do stuff to the AC as needed 
    
    # work is done set. automatic activity to completed. 
    set-scsmobject $thisAC -property Status -Value $ActCompleted</ScriptBody>
                    <SnapIns></SnapIns>
                    <Parameters>
                      <Parameter>
                        <Name>ID</Name>
                        <Value>$Config/ID$</Value>
                      </Parameter>
                    </Parameters>
                    <TimeoutSeconds>300</TimeoutSeconds>
                    <StrictErrorHandling>true</StrictErrorHandling>
                    <SerializationDepth>3</SerializationDepth>
                  </WriteAction>
    

    you can see, the parameter $ID contains the work item id string (i.e. "AC4321"), and i'm using that to get the Activity using Get-SCSMObject and the Filter property that looks for the ID in question. 

    be careful how frequently you run this, as the script will trigger each time your criteria is match. if that's too wide of a selection, then you'll get performance issues. 

    Thursday, December 25, 2014 4:37 PM