none
Assign a Service Request to User Who Put it On Hold Status RRS feed

  • Question

  • We don't assign Service Requests to analysts but assign the Activities within the SR to analysts.  When a SR is put on hold though, we would like the Analyst to assign it to themselves so have a go to as to why it is on hold in case the notes aren't complete, but this doesn't always happen.

    I see when a SR is put On Hold, it adds the note in Implementation Notes under Results tab and make an entry in the History tab but is there a way to use that data to assign the SR (via Orchestrator, etc) to the user who put it on hold. In Orchestrator I can find the notes and everything I need except that history line that contains the user name who put it on hold. 

    Any ideas would be great! Thanks!

    Friday, May 19, 2017 1:15 PM

Answers

  • Hi

    Here is a PowerShell script that will assign an SR to the last person to put the SR On Hold.

    It assumes that all users are in the one domain, as it does a cleanup operation on the User Name from the History tab. It also requires that you have an SR ID as an input when you run the script.

    You can use Orchestrator or a custom workflow that triggers on an SR going from InProgress to OnHold. Have a look at the blog post from Mathew Dowst:  SCSM PowerShell: Creating PowerShell Workflows 

    Here is the script:

    Import-Module SMLets -Force #You will need to set this to the SR ID $WorkItemID = "SR132"

    #This should work in a custom workflow, but has not been tested
    #$WorkItemID = Get-SCSMClassInstsance -Id $id 

    $WorkItemClass = Get-SCSMClass System.WorkItem.ServiceRequest$ $WorkItemObject = Get-SCSMObject -Class $WorkItemClass -Filter "Id -eq $WorkItemID " $UserClass = Get-SCSMClass -name System.Domain.User$ $AssignedToRelClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$ $InprogressEnum = Get-SCSMEnumeration ServiceRequestStatusEnum.InProgress $OnHoldEnum = Get-SCSMEnumeration ServiceRequestStatusEnum.OnHold #Get the History from the SR $History = Get-SCSMObjectHistory -Object $WorkItemObject #Loop through each Change made in the History # Followed by another loop of each update made in the Change - there can be multiple values updated in each comment # The loop writes-host the updates to the screen for troubleshooting foreach ($Change in $History.History )  { foreach ($Update in $Change.Changes )   { If ($Update.OldValue.value -eq $InprogressEnum -and $Update.NewValue.value -eq $OnHoldEnum ) { Write-host "Comment entered by $($Change.Username) " $Update | FL $AssignedToUser = $Change.Username } #End of If update is status From InProgress to OnHold   } #End of For Update in Change  } #End of For Change in History #The assignedtouser variable is in the format DomainName\Username and we only want the username portion $Domain = Get-ADDomain $AssignedToUser = $AssignedToUser -replace "$($Domain.NetBIOSName)\\", "" #Get the SCSM User Object based on username only $UserObject = Get-SCSMObject -Class $UserClass -Filter "Username -eq $($AssignedToUser)" #Assign the SR to the User New-SCSMRelationshipObject -RelationShip $AssignedToRelClass -Source $WorkItemObject -Target $UserObject -Bulk

    Regards

    Glen


    Web: www.xapity.com  |   Twitter: @xapityapps  |   Facebook: xapityapps





    • Edited by Glen.Xapity Saturday, May 20, 2017 1:04 AM
    • Marked as answer by ihcc2uni Tuesday, May 23, 2017 10:12 PM
    Friday, May 19, 2017 11:48 PM

All replies

  • Hi

    Here is a PowerShell script that will assign an SR to the last person to put the SR On Hold.

    It assumes that all users are in the one domain, as it does a cleanup operation on the User Name from the History tab. It also requires that you have an SR ID as an input when you run the script.

    You can use Orchestrator or a custom workflow that triggers on an SR going from InProgress to OnHold. Have a look at the blog post from Mathew Dowst:  SCSM PowerShell: Creating PowerShell Workflows 

    Here is the script:

    Import-Module SMLets -Force #You will need to set this to the SR ID $WorkItemID = "SR132"

    #This should work in a custom workflow, but has not been tested
    #$WorkItemID = Get-SCSMClassInstsance -Id $id 

    $WorkItemClass = Get-SCSMClass System.WorkItem.ServiceRequest$ $WorkItemObject = Get-SCSMObject -Class $WorkItemClass -Filter "Id -eq $WorkItemID " $UserClass = Get-SCSMClass -name System.Domain.User$ $AssignedToRelClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$ $InprogressEnum = Get-SCSMEnumeration ServiceRequestStatusEnum.InProgress $OnHoldEnum = Get-SCSMEnumeration ServiceRequestStatusEnum.OnHold #Get the History from the SR $History = Get-SCSMObjectHistory -Object $WorkItemObject #Loop through each Change made in the History # Followed by another loop of each update made in the Change - there can be multiple values updated in each comment # The loop writes-host the updates to the screen for troubleshooting foreach ($Change in $History.History )  { foreach ($Update in $Change.Changes )   { If ($Update.OldValue.value -eq $InprogressEnum -and $Update.NewValue.value -eq $OnHoldEnum ) { Write-host "Comment entered by $($Change.Username) " $Update | FL $AssignedToUser = $Change.Username } #End of If update is status From InProgress to OnHold   } #End of For Update in Change  } #End of For Change in History #The assignedtouser variable is in the format DomainName\Username and we only want the username portion $Domain = Get-ADDomain $AssignedToUser = $AssignedToUser -replace "$($Domain.NetBIOSName)\\", "" #Get the SCSM User Object based on username only $UserObject = Get-SCSMObject -Class $UserClass -Filter "Username -eq $($AssignedToUser)" #Assign the SR to the User New-SCSMRelationshipObject -RelationShip $AssignedToRelClass -Source $WorkItemObject -Target $UserObject -Bulk

    Regards

    Glen


    Web: www.xapity.com  |   Twitter: @xapityapps  |   Facebook: xapityapps





    • Edited by Glen.Xapity Saturday, May 20, 2017 1:04 AM
    • Marked as answer by ihcc2uni Tuesday, May 23, 2017 10:12 PM
    Friday, May 19, 2017 11:48 PM
  • Works perfect, thanks!
    Tuesday, May 23, 2017 10:13 PM