Home Powershell Activity

Service Request created with PowerShell cannot be completed

Robin_FaklerRobin_Fakler Customer IT Monkey ✭
edited October 2019 in Powershell Activity

Hello everybody,

I cannot set the status of created Service Requests with PowerShell to "Completed". I´m only able to choose between "Cancel" and "Put On Hold".

When I create a SR directly from the used template, I can set the status to "Completed". The template does not contain any activities.


Do you have any ideas?


Here is the script that I use for creating SRs:


    # get the service request class
    $serviceRequestClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$

    # set service request parameters
    $SRHashTable = @{
    Title = "Test Title";
    Description = "Test Description";
    ID = "SR{0}";
    }

    # create initial service request
    $newServiceRequest = New-SCSMOBject -Class $serviceRequestClass -PropertyHashtable $SRHashTable -PassThru
    $serviceRequestId = $newServiceRequest.ID

    # get the service request type projection
    $serviceRequestTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$

    # get the service request created earlier in a form where we can apply the template
    $serviceRequestProjection = Get-SCSMObjectProjection -ProjectionName $serviceRequestTypeProjection.Name -filter "ID -eq $serviceRequestId"

    # get the service request template
    $serviceRequestTemplate = Get-SCSMObjectTemplate -DisplayName "SR - Test"

    # apply the template to the service request
    Set-SCSMObjectTemplate -Projection $serviceRequestProjection -Template $serviceRequestTemplate

Best Answer

  • Brian_WiestBrian_Wiest Super IT Monkey ✭✭✭✭✭
    Accepted Answer

    When creating SR's via PowerShell the SCSM workflow engine doesn't progress thru checking for activities. So you will see that the WI is current "In Progress" for status. "In Progress" means the WI is expecting activities to manage the request, hence why you cannot complete the request. Now if you place the WI on hold, wait for workflow, then activate again. You will see the status go to "In Progress" then to "Submitted" as you would when to create a new SR from a template. How to manage this in PowerShell is to define the status on the create array.

    Add the enumeration at the top were you get your class

    $serviceRequestStatusSubmitted = Get-SCSMEnumeration -Name ServiceRequestStatusEnum.Submitted

    Then add to your array

    Status = $serviceRequestStatusSubmitted;

    HTH

Answers

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    Accepted Answer

    When creating SR's via PowerShell the SCSM workflow engine doesn't progress thru checking for activities. So you will see that the WI is current "In Progress" for status. "In Progress" means the WI is expecting activities to manage the request, hence why you cannot complete the request. Now if you place the WI on hold, wait for workflow, then activate again. You will see the status go to "In Progress" then to "Submitted" as you would when to create a new SR from a template. How to manage this in PowerShell is to define the status on the create array.

    Add the enumeration at the top were you get your class

    $serviceRequestStatusSubmitted = Get-SCSMEnumeration -Name ServiceRequestStatusEnum.Submitted

    Then add to your array

    Status = $serviceRequestStatusSubmitted;

    HTH

  • Robin_FaklerRobin_Fakler Customer IT Monkey ✭

    Perfect, thank you very much!

Sign In or Register to comment.