locked
Adding RA with SCORCH or powershell to an existing SR causes the workflow to be stuck. RRS feed

  • Question

  • Hi,
     
    I've created a Runbook that will add review activities to a Create-User SR. This should be used to flag important groupdrives and need to be reviewed before the user gets permissions to these group drives.
     
    From the moment this RA is added, the workflow will not work anymore and will be stuck on pending. The next step after the previous completed step will no longer be triggered for some reason.
    Even correcting the sequence ID's does not fix this.
     
    Example in the added picture: The RA that was added was "[RA] RG.FS.Warehouse2: FLAG important Groupdrive: Owner Review"
    Everything after this will not be triggered. (even if I change the sequence ID to 0. Nothing will be triggered after the activity was added.
     
    Isn't it possible to add a RA to an existing SR 
    Thanks!



    Wednesday, October 17, 2018 6:16 AM

Answers

  • Found the solution to run the runbook. There was something going wrong mapping the SR-ID to a variable. Probably too many "".

    Thanks!
    Wednesday, October 17, 2018 2:55 PM

All replies

  • And creating the review-activity in advance, than skipping is not perfect for this SR, because we need to have a review-activity for each flagged groupdrive, thats why one should be created and added each time.

    I hope there's a possibility !

    Kind regards
    Wednesday, October 17, 2018 6:30 AM
  • I can't see the attached screenshot, sorry. 

    Andreas Baumgarten

    Wednesday, October 17, 2018 7:32 AM
  • Yes. My account needs further verification, so it seems. Before I can add images.
    Wednesday, October 17, 2018 8:31 AM
  • I found a way to do this via Powershell. Now when I want to create a remote-connection and run the script it will return this:

    Processing data for a remote command failed with the following error message: The WSMan provider host process did not return a proper response.  A provider in
    the host process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OperationStopped: (BEXXVWPMG10:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : JobFailure
        + PSComputerName        : BEXXVWPMG10

    Kind of a random error I noticed : )
    Wednesday, October 17, 2018 9:51 AM
  • The WSman Provider is properly configured on the target computer you are using for the remote-connection?

    Firewall is enabled? 


    Andreas Baumgarten

    Wednesday, October 17, 2018 10:30 AM
  • $resultArray = Invoke-Command -Session $PSsession -Scriptblock{

    Import-Module 'C:\Program Files\Microsoft System Center 2012 R2\Service Manager\Powershell\System.Center.Service.Manager.psd1' -force


    $ID = "SR461466"
    $SRClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$
    $SR = Get-SCSMobject -Class $SRClass -filter "ID -eq $ID"
    #$SRClass = Get-SCSMClass -name System.WorkItem.ServiceRequest
    $RAClass = Get-SCSMClass -name System.WorkItem.Activity.ReviewActivity


    Function Sequence-Activities
    {
        param (
            [Parameter(Mandatory=$True,Position=1)] [string]$Id,
            [parameter(Mandatory=$True,ParameterSetName="set1")] [int]$SequenceId,
            [parameter(Mandatory=$True,ParameterSetName="set2")] [System.Management.Automation.SwitchParameter]$First,
            [parameter(Mandatory=$True,ParameterSetName="set3")] [System.Management.Automation.SwitchParameter]$Last
        )

        # Get the Work Item
        $WI = Get-SCSMobject -Class $SRClass -filter "ID -eq $ID"

        # Get the Contains Activity relationship
        $ActivityRelationship = Get-SCRelationship -name System.WorkItemContainsActivity

        # Get Related Activities
        $Activities = $WI.GetRelatedObjectsWhereSource($ActivityRelationship.ID).EnterpriseManagementObject.Id.Guid

        if($Activities)
        {
            If($First)
            {
                # Increment all existing activities by 1 and return 0
                Get-SCClassInstance -id $Activities | %{$_.SequenceId=$($_.SequenceId+1);$_} | Update-SCClassInstance
                Return 0
            }
            elseif($Last)
            {
                # Get the last SequenceId and increment it
                $SequenceId = (Get-SCClassInstance -id $Activities | sort SequenceId | select -Last 1).SequenceId
                $SequenceId++
                Return $SequenceId
            }
            else
            {
                Get-SCClassInstance -id $Activities | ?{$_.SequenceId -ge $SequenceId} | %{$_.SequenceId=$($_.SequenceId+1);$_} | Update-SCClassInstance
                Return $SequenceId
            }

        }
        else
        {
            Return 0
        }
    }

    # Get the Sequence Id
    $SequenceId = Sequence-Activities -Id $Id -SequenceId 4

    # Get the required classes
    $SRClass = Get-SCSMClass -name System.WorkItem.ServiceRequest
    $RAClass = Get-SCSMClass -name System.WorkItem.Activity.ReviewActivity

    # Manaual Acitivty Prefix
    $RAPrefix = (Get-SCClassInstance -class (Get-SCClass -Name System.GlobalSetting.ActivitySettings)).SystemWorkItemActivityReviewActivityIdPrefix

    # Get the Service Request
    $SR = Get-SCSMClassInstance -Class $SRClass | ?{$_.ID -eq $ID}

    # Get the Contains Activity relationship
    $ActivityRelationship = Get-SCRelationship -name System.WorkItemContainsActivity

    # Set the properties for the Manual Activity
    $MAProperty = @{
        Id = "$RAPrefix{0}"
        SequenceId = $SequenceId
        Title = "[RA] Test"
        }

    # Create the Manaual Activity and Relate it to the Service Request
    New-SCRelationshipInstance -RelationshipClass $ActivityRelationship -Source $SR -TargetClass $MAClass -TargetProperty $MAProperty -PassThru
    Return $resultArray
    }


    This is wat should be ran. This works when ran locally from the scsm-server.

    When I want to run it remotely it freezes (doesn't stop running without doing anything) or gives an error. I even imported smlets to try locally on the scorch-server, but get-scsmclassinstance can't be used. Which I need to run this script.

                
    Wednesday, October 17, 2018 12:41 PM
  • Now I got this.

    Exception of type 'System.OutOfMemoryException' was thrown.
        + CategoryInfo          : NotSpecified: (Microsoft.Syste...InstanceCommand:GetSCClassInstanceCommand) [Get-SCClassInstance], OutOfMemoryException
        + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.Core.Commands.GetSCClassInstanceCommand
        + PSComputerName        : BEXXVWPMG10
    Wednesday, October 17, 2018 12:53 PM
  • Ok. Got this to work by using

    $SR = Get-SCSMClassInstance -Class $SRClass -Filter "Id -eq $ID"  Instead of Get-SCSMClassInstance -Class $SRClass | ?{$_.ID -eq $ID}.

    new problem arises now. I can run this via powershell, but when it's triggered by a runbook. It won't create the review-activity, yet will close succesfully.
    Wednesday, October 17, 2018 2:01 PM
  • Instead of "get-scsmclassinstance" the cmdlet "Get-SCSMobject" in Smlets does not work?



    Andreas Baumgarten

    Wednesday, October 17, 2018 2:03 PM
  • No. I's not possible to get the activites that way.
    $Activities = $WI.GetRelatedObjectsWhereSource($ActivityRelationship.ID).EnterpriseManagementObject.Id.Guid

    But it's seems to work now. Now I need find a way to get it to work via ORchestrator.
    Wednesday, October 17, 2018 2:10 PM
  • Found the solution to run the runbook. There was something going wrong mapping the SR-ID to a variable. Probably too many "".

    Thanks!
    Wednesday, October 17, 2018 2:55 PM