locked
How to auto-assign user workitem if "assigned user"-field is empty when closing it? RRS feed

  • Question

  • Hello everybody

    We often have the case that one of our colleagues closes a workitem but doesnt assign himself to the workitem, what is really annoying.

    We would like to automate that with a Orchestrator Runbook but don't know exactly how to achieve that (there are a lot steps I think).

    Does anybody did that before?

    Thanks and best regards

    Monday, October 30, 2017 10:21 AM

Answers

  • Hi

    Sorry missed that one. Good catch.

    SR's go through a different workflow and when you said Resolved I immediately thought of IR where it is a status.

    The status values for a Service Request are:

      Get-SCSMEnumeration -Name ServiceRequestStatusEnum

    ordinal name                                displayname           
    ------- ----                                -----------           
    5       ServiceRequestStatusEnum.New             New                   
    40      ServiceRequestStatusEnum.Closed         Closed                
    25      ServiceRequestStatusEnum.Completed   Completed             
    30      ServiceRequestStatusEnum.Failed          Failed                
    35      ServiceRequestStatusEnum.Canceled     Cancelled             
    20      ServiceRequestStatusEnum.OnHold        On Hold               
    15      ServiceRequestStatusEnum.InProgress   In Progress           
    10      ServiceRequestStatusEnum.Submitted   Submitted             

    When all the activities on a SR are completed a system workflow will complete the SR automatically. There is no user that resolved the SR.

    The best way is to get SCSM Entity Explorer and look atr one of the SR's and see what relationships are on it.

    You can get information that looks like this:

    Regards

    Glen


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

    Friday, November 3, 2017 9:33 AM

All replies

  • Hi

    I am not sure a runbook is the best option here as the workitem will be already be closed. I would look at a scheduled PowerShell task that runs once a day (or on an schedule you prefer).

    Also when you say closed do you mean completed ie workitem goes from In Progress -> Completed or do you mean the workitem goes from Completed -> Closed?

    This code is for Service requests that go Completed -> Closed, but could be modified for the In Progress to Completed.

    # The multiple Criteria part modified from  http://www.lazywinadmin.com/2016/03/powershellscsm-get-manual-activities.html
    
    # Import Smlets Module
    Import-module -name Smlets
    
    # Get the Service Request Class
    $SRClass = Get-SCSMClass -Name System.WorkItem.ServiceRequest$
    
    # Get the Service Request Completed Status Enumeration
    $SRStatusClosed = Get-SCSMEnumeration -Name ServiceRequestStatusEnum.Closed$
    
    # Get the starting date from where we are searching
    $SRClosedDay = (Get-date).Adddays(-1)
    
    # Get the Criteria Class
    $CriteriaClass = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
    
    # Define the Filter
    $Filter = "Status = '$($SRStatusClosed.Id)' AND ClosedDate > '$SRClosedDay'"
    
    # Create the Criteria Object
    $CriteriaObject = new-object $CriteriaClass $Filter, $SRClass
    
    # Collect all Closed Service Requests in the last day
    $Workitems = Get-SCSMObject -criteria $CriteriaObject
    
    
    $AssignedToUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
    $ClosedByUserRel = Get-SCSMRelationshipClass -Name System.WorkItemClosedByUser
    
    
    #Loop through each Service Request checking the Assigned To and Closed To values
    ForEach ($SR in $Workitems)
      {
           $AssignedTo = Get-SCSMRelatedObject -Relationship $AssignedToUserRel -SMObject $SR
           Write-Host "$AssignedTo"
           $ClosedBy = Get-SCSMRelatedObject -Relationship $ClosedByUserRel -SMObject $SR
            Write-Host "$ClosedBy"
           If ($AssignedTo -ne $ClosedBy) 
             {New-SCSMRelationshipObject -Relationship $AssignedToUserRel -Source $SR -Target $ClosedBy  -Bulk }
    
      } #End ForEach loop
    


    Regards

    Glen


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

    • Proposed as answer by Yan Li_ Thursday, November 2, 2017 7:22 AM
    Monday, October 30, 2017 9:07 PM
  • Hi Glen, many thanks for your Script it works very well!

    Is it also possible to do it for resolved tickets than closed ones?

    I know that there is a SCSMEnumeration "IncidentStatusEnum.Resolved" for example.

    But I don't know if I can find the relating user who resolved it, because in "SCSMRelationshipClass" I can only find "System.WorkItem.TroubleTicketResolvedByUser", would that work anyhow?

    Thanks and best regards

    Silas 

    Thursday, November 2, 2017 9:55 AM
  • Hi

    Yes that would work.

    Get the Incident Class: System.WorkItem.Incident 

    Use ReslovedDate and the IncidentStatusEnum.Resolved in the criteria

    And System.WorkItem.TroubleTicketResiolvedByUser is the correct relationship to use. Assigned to is the same on incidents as service requests (or any work item).

    You should be able to replace them in the script above. I will post a script tomorrow when I get more time.

    To work out details like this, have a look at  Tools SCSM Customizations Classes How to use SCSM Entity Explorer 

    SCSM Entity Explorer is really useful to see the relationships using real data. Once you get the hang of it you can see exactly how the work item is constructed and it becomes the first thing to check when you run into problems like this.

    Regards

    Glen


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


    • Edited by Glen.Xapity Thursday, November 2, 2017 11:01 AM
    Thursday, November 2, 2017 11:00 AM
  • Hi

    This powershell code should work. It gets incidents in the last 24 hours that have been resolved. Then checks the assigned to and resolved by and if they are not equal, assigns the resolved by user to the Assigned To user.

    # The multiple Criteria part modified from  http://www.lazywinadmin.com/2016/03/powershellscsm-get-manual-activities.html
    
    # Import Smlets Module
    Import-module -name Smlets
    
    # Get the Incident Class
    $IRClass = Get-SCSMClass -Name System.WorkItem.Incident$
    
    # Get the Incident Resolved Status Enumeration
    $IRStatusResolved = Get-SCSMEnumeration -Name IncidentStatusEnum.Resolved$
    
    # Get the starting date from where we are searching
    $IRClosedDay = (Get-date).Adddays(-1)
    
    # Get the Criteria Class
    $CriteriaClass = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
    
    # Define the Filter
    $Filter = "Status = '$($IRStatusResolved.Id)' AND ResolvedDate > '$IRClosedDay'"
    
    # Create the Criteria Object
    $CriteriaObject = new-object $CriteriaClass $Filter, $IRClass
    
    # Collect all Resolved Incidents in the last day
    $Workitems = Get-SCSMObject -criteria $CriteriaObject
    
    
    $AssignedToUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
    $ResolvedByUserRel = Get-SCSMRelationshipClass -Name System.WorkItem.TroubleTicketResolvedByUser
    
    
    #Loop through each Incident checking the Assigned To and Resolved By values.
    ForEach ($IR in $Workitems)
      {
           $AssignedTo = Get-SCSMRelatedObject -Relationship $AssignedToUserRel -SMObject $IR
           Write-Host "$AssignedTo"
           $ResolvedBy = Get-SCSMRelatedObject -Relationship $ResolvedByUserRel -SMObject $IR
            Write-Host "$ResolvedBy"
           If ($AssignedTo -ne $ClosedBy) 
             {New-SCSMRelationshipObject -Relationship $AssignedToUserRel -Source $IR -Target $ResolvedBy  -Bulk }
    
      } #End ForEach loop

    Regards

    Glen


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


    Thursday, November 2, 2017 7:45 PM
  • Many thanks for the code Glen!

    I changed "If ($AssignedTo -ne $ClosedBy)" to "If ($AssignedTo -ne $ResolvedBy)" and it run properly!

    I'm trying to do the same for SRs, here is my code, which does not work properly:

    # The multiple Criteria part modified from  http://www.lazywinadmin.com/2016/03/powershellscsm-get-manual-activities.html
    
    # Import Smlets Module
    Import-module -name Smlets
    
    # Get the Incident Class
    $SRClass = Get-SCSMClass -Name System.WorkItem.ServiceRequest$
    
    # Get the Incident Resolved Status Enumeration
    $SRStatusResolved = Get-SCSMEnumeration -Name ServiceRequestStatusEnum.Completed$
    
    # Get the starting date from where we are searching
    $SRClosedDay = (Get-date).Adddays(-1)
    
    # Get the Criteria Class
    $CriteriaClass = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
    
    # Define the Filter
    $Filter = "Status = '$($SRStatusResolved.Id)' AND CompletedDate > '$SRClosedDay'"
    
    
    # Create the Criteria Object
    $CriteriaObject = new-object $CriteriaClass $Filter, $SRClass
    
    # Collect all Resolved Incidents in the last day
    $Workitems = Get-SCSMObject -criteria $CriteriaObject
    
    
    $AssignedToUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
    $ResolvedByUserRel = Get-SCSMRelationshipClass -Name System.WorkItem.TroubleTicketResolvedByUser
    
    
    #Loop through each Incident checking the Assigned To and Resolved By values.
    ForEach ($SR in $Workitems)
      {
           $AssignedTo = Get-SCSMRelatedObject -Relationship $AssignedToUserRel -SMObject $SR
           Write-Host "$AssignedTo"
           $ResolvedBy = Get-SCSMRelatedObject -Relationship $ResolvedByUserRel -SMObject $SR
            Write-Host "$ResolvedBy"
           If ($AssignedTo -ne $ResolvedBy) 
             {New-SCSMRelationshipObject -Relationship $AssignedToUserRel -Source $SR -Target $ResolvedBy  -Bulk }
    
      } #End ForEach loop

    Unfortunately I cannot find any SCSMRelationshipClass which is something like "completed" for SRs..

    Many thanks and best regards

    Silas

    Friday, November 3, 2017 9:22 AM
  • Hi

    Sorry missed that one. Good catch.

    SR's go through a different workflow and when you said Resolved I immediately thought of IR where it is a status.

    The status values for a Service Request are:

      Get-SCSMEnumeration -Name ServiceRequestStatusEnum

    ordinal name                                displayname           
    ------- ----                                -----------           
    5       ServiceRequestStatusEnum.New             New                   
    40      ServiceRequestStatusEnum.Closed         Closed                
    25      ServiceRequestStatusEnum.Completed   Completed             
    30      ServiceRequestStatusEnum.Failed          Failed                
    35      ServiceRequestStatusEnum.Canceled     Cancelled             
    20      ServiceRequestStatusEnum.OnHold        On Hold               
    15      ServiceRequestStatusEnum.InProgress   In Progress           
    10      ServiceRequestStatusEnum.Submitted   Submitted             

    When all the activities on a SR are completed a system workflow will complete the SR automatically. There is no user that resolved the SR.

    The best way is to get SCSM Entity Explorer and look atr one of the SR's and see what relationships are on it.

    You can get information that looks like this:

    Regards

    Glen


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

    Friday, November 3, 2017 9:33 AM