Home Service Manager

Change request: Updating "Assigned to" to "Created By" user automatically

Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

Hi guys,

Not great at Runbooks or PowerShell but having trouble working with Change requests in either.


Has anyone got or seen a working example of either in PowerShell or in a runbook where you could have it update the Assigned To field to match the Created By field?


We are looking at standard changes and don't want to have to make people assign themselves to the change.

TIA.

Best Answers

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

    Use the Cireson PowerShell activity, as the first activity of the CR process


    Param([guid]$id)

    Import-Module SMLets

    $crcl = get-scsmclass -name system.workitem.changerequest$

    $cr = get-scsmobject -class$crcl -filter"id -eq '$id'"

    $createdByRel = Get-SCSMRelationshipClass -name system.workitemcreatedbyuser$

    $createdyByUser = get-scsmrelatedobject -SMObject $cr -Relationship $createdByRel

    $assignedByRel = get-scsmrelationshipclass -name system.workitemassignedtouser$

    New-SCSMRelationshipObject -Relationship $assignedByRel -source $cr -target $createdyByUser -bulk

    Remove-Module SMlets

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    Answer ✓

    @Alfie_Thomas

    The filter in the first acivity is wrong:

    Yours is: "Related Class equals Created By User", but it should be "RELATIONSHIP Class equals Created by User".


    if you change it to that value, it should work.

Answers

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

    Use the Cireson PowerShell activity, as the first activity of the CR process


    Param([guid]$id)

    Import-Module SMLets

    $crcl = get-scsmclass -name system.workitem.changerequest$

    $cr = get-scsmobject -class$crcl -filter"id -eq '$id'"

    $createdByRel = Get-SCSMRelationshipClass -name system.workitemcreatedbyuser$

    $createdyByUser = get-scsmrelatedobject -SMObject $cr -Relationship $createdByRel

    $assignedByRel = get-scsmrelationshipclass -name system.workitemassignedtouser$

    New-SCSMRelationshipObject -Relationship $assignedByRel -source $cr -target $createdyByUser -bulk

    Remove-Module SMlets

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭

    @Alfie_Thomas You could accomplish that with a monitoring runbook.

    Every time a new change is created, you invoke the following runbook:

    1. Add a Get Object Activity and set the class to change request
    2. The criteria for the change is the SC Object GUID from the Monitoring Runbook
    3. Add a "Get Relationship" Activity, where Source Class is Change Request, the GUID is the GUID from the change and the 2nd class is Active Directory User
    4. Add a Get Object Activity and set the object class to Active Directory User and the Condition to "SC Object GUID equals Related Object GUID(from the Relationship Activity before)"
    5. In the Link from the Relationship to the User set the Condition at "Include" to the following: Relationship Class equals Created By User.
    6. Then add a Create Relationship Activity --> Source Class is Change, Target Class is Active Directory User , GUIDs are the respective ones from the Get Object Activities before. And the Relationship Class is "Assigned To"


    Now everytime a Change is created, the Created By User will be the Assigned To user shortly after. You could also create a standard runbook (without monitoring) and add it to the template of the change.

    Note that it is also possible to just create the get and add relationship activities and accomplish what you need. But when you are not experienced with runbooks, this is a good start :)

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Brian,

    Thanks for this. Added all this but it still creates the change request and doesn't add the Created by user to the Assigned to. Could I be missing something or how would you diagnose an issue?


    Regards,

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Simon,

    Thanks for this. Built this out and got pretty close but getting the message below for the create relationship activity - Any ideas?

    Error:


    Create relationship activity setup:

    Get object activity:

    Get relationship activity:


    Get SC Object Guid:


    Monitor Object activity: (have it set to updated when testing as quicker)


    Regards,

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    edited May 2022

    Do you have the SMLets Module installed for all users? Log into the primary management server as the workflow account verify/install SMLets.

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    For the Runbook

    Recommend for testing you make the first object a specific CR so you can use the runbook tester to walk thru the logic and see what the system returns.

    Step 1. Do not recommend on updated. If someone reassigns the CR the runbook will reassign back to the creator. Unless this is just for your testing.

    Step 2 your do not need as you will have your CR GUID from step 1.

    The link between step 3 and 4 will still pass everything. You want to only include the one relationship class. (Hence the three Get Objects in the screenshot)

    Step 4 is not needed as you will have your user GUID from the get relationship


  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Brian - Again thank you for baring with me.

    Only have it as updated for tested. Have removed the not needed but it completed the first two steps and just finishes. What have I missed?


    regards,

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited May 2022

    @Alfie_Thomas

    In the "Create relationship" you have to use the following:


    Source Object GUID: SC Object GUID from "Monitor Object"

    Target Object GUID: Related Object GUID from Get Relationship


    @Brian_Wiest IMO in the beginning it is better to get the object after the relationship, to learn the functionality of the SCO Activities :) That's why I have shown it that way ;)

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    In the create relationship, the source needs the be the monitor object SC GUID.

    And the Target needs to be the Related Object GUID from Get relationship.

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    @Simon_Zeinhofer Yea that is a personal preference. Each person should decide what works best for their environment. Cutting down the Get objects cuts down on your data reads for the SQL server. If you only have a couple runbooks that is one thing, but if you have hundreds that can add up.

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Thanks both.


    Updated and still sits on the Get relationship:






  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    The last screenshot shows the workflow completed. And that the filter line between Get and Create didn't find a match. Click the Show Details and it will provide the data it gathered in the Get Relationship. There you can make sure the returned values match the filter.

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Checking and it seems like they don't match so I thought that would trigger it to update the change to be the Createby user is the assigned to user?


    Regards,



  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi both,


    Any ideas on this one? PSA activity just sits on In progress and Runbook still not moving.


    TIA,

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    Answer ✓

    @Alfie_Thomas

    The filter in the first acivity is wrong:

    Yours is: "Related Class equals Created By User", but it should be "RELATIONSHIP Class equals Created by User".


    if you change it to that value, it should work.

Sign In or Register to comment.