Can you create a service request from another service request activity

Bryant_RichardsBryant_Richards Customer IT Monkey ✭
We are working on a new user offboarding Service Request, is it possible to create a new SR from an activity? We have some policies that have their own ticket types and we want to have them as separate tickets that will be created when it gets to their activity. Is that possible and if so how would we do it?

Best Answer

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    edited December 2017 Accepted Answer
    We have this setup for one of our support groups. 
    Creates a new SR via PowerShell Activity.
    Note make sure the first SR with the P$A has other activities so this do not auto complete.

    Param([guid]$WorkItemID)
    
    import-module smlets
    
    #Get the Service Request Class
    $serviceRequestClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$
    $serviceRequestPriority = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Low
    $serviceRequestUrgency = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Low
    
    $Object = Get-SCSMObject -Class $serviceRequestClass -Filter "ID -eq '$WorkItemID'"
    
    Write-Output $WorkItemID
    Write-Output $Object.Title 
    
    $affectedUserRelClass = Get-SCSMRelationshipClass System.WorkItemAffectedUser$
    
    $affectedUser = Get-SCSMRelatedObject -SMObject $Object -Relationship $AffectedUserRelClass
    
    
    $SRHashTable = @{
    Title = "New User " + $Object.Title;
    Description = $Object.Description;
    ID = "SR{0}";
    Urgency = $serviceRequestUrgency;
    Priority = $serviceRequestPriority;
    }
    
    #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 “New User SR”
    
    #Apply the template to the Service Request
    Set-SCSMObjectTemplate -Projection $serviceRequestProjection -Template $serviceRequestTemplate
    
    #Set affected user
    $AffectedUserRel = get-scsmrelationshipclass -name System.WorkItemAffectedUser$
    New-SCSMRelationshipObject -Relationship $AffectedUserRel -Source $newServiceRequest -Target $affectedUser -Bulk
    
    $RWIClass = Get-SCSMRelationshipClass -Name System.WorkItemRelatesToWorkItem$
    New-SCSMRelationshipObject -Relationship $RWIClass -Source $Object -Target $newServiceRequest -Bulk
    New-SCSMRelationshipObject -Relationship $RWIClass -Source $newServiceRequest -Target $Object -Bulk
    
    Remove-Module SMlets


    Just update you SR Template title to meet your environment.

Answers

  • Adam_DzyackyAdam_Dzyacky Customer Contributor Monkey ✭✭✭✭✭
    edited December 2017
    Yes - that activity is going to be either an SCO runbook, SMA runbook, or a Cireson P$A. Then the runbook when executed could feature PowerShell that knows how to grab the parent work item it came from (e.g. the original SR). Then that runbook could execute PowerShell that does something to the effect of:

    New-SCSMObject -class "System.WorkItem.ServiceRequest$" -propertyhashtable $propHash

    Thereby creating a new SR with the option of setting multiple properties through the property hashtable. You could also apply a template, etc.

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    edited December 2017 Accepted Answer
    We have this setup for one of our support groups. 
    Creates a new SR via PowerShell Activity.
    Note make sure the first SR with the P$A has other activities so this do not auto complete.

    Param([guid]$WorkItemID)
    
    import-module smlets
    
    #Get the Service Request Class
    $serviceRequestClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$
    $serviceRequestPriority = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Low
    $serviceRequestUrgency = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Low
    
    $Object = Get-SCSMObject -Class $serviceRequestClass -Filter "ID -eq '$WorkItemID'"
    
    Write-Output $WorkItemID
    Write-Output $Object.Title 
    
    $affectedUserRelClass = Get-SCSMRelationshipClass System.WorkItemAffectedUser$
    
    $affectedUser = Get-SCSMRelatedObject -SMObject $Object -Relationship $AffectedUserRelClass
    
    
    $SRHashTable = @{
    Title = "New User " + $Object.Title;
    Description = $Object.Description;
    ID = "SR{0}";
    Urgency = $serviceRequestUrgency;
    Priority = $serviceRequestPriority;
    }
    
    #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 “New User SR”
    
    #Apply the template to the Service Request
    Set-SCSMObjectTemplate -Projection $serviceRequestProjection -Template $serviceRequestTemplate
    
    #Set affected user
    $AffectedUserRel = get-scsmrelationshipclass -name System.WorkItemAffectedUser$
    New-SCSMRelationshipObject -Relationship $AffectedUserRel -Source $newServiceRequest -Target $affectedUser -Bulk
    
    $RWIClass = Get-SCSMRelationshipClass -Name System.WorkItemRelatesToWorkItem$
    New-SCSMRelationshipObject -Relationship $RWIClass -Source $Object -Target $newServiceRequest -Bulk
    New-SCSMRelationshipObject -Relationship $RWIClass -Source $newServiceRequest -Target $Object -Bulk
    
    Remove-Module SMlets


    Just update you SR Template title to meet your environment.
  • Adam_DzyackyAdam_Dzyacky Customer Contributor Monkey ✭✭✭✭✭
    edited December 2017
    @Brian_Wiest - crushed it.
  • Adam_DzyackyAdam_Dzyacky Customer Contributor Monkey ✭✭✭✭✭
    Hey @Joe_Burrows - what if there was an "SMlets" or "PowerShell" section of the community to help centralize these kinda things into that weren't full blown GitHub like projects and instead...well just these kind of things?
  • Joe_BurrowsJoe_Burrows Cireson Devops Super IT Monkey ✭✭✭✭✭
    Hey @Joe_Burrows - what if there was an "SMlets" or "PowerShell" section of the community to help centralize these kinda things into that weren't full blown GitHub like projects and instead...well just these kind of things?
    Hey,
    Added now:
    https://community.cireson.com/categories/powershell
Sign In or Register to comment.