Change request: Updating "Assigned to" to "Created By" user automatically
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_Wiest Customer Super IT Monkey ✭✭✭✭✭
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
0 -
Simon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
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.
0
Answers
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
@Alfie_Thomas You could accomplish that with a monitoring runbook.
Every time a new change is created, you invoke the following runbook:
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 :)
I'd certainly recommend the following - https://community.cireson.com/discussion/5681/definitive-service-manager-powershell
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,
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,
Do you have the SMLets Module installed for all users? Log into the primary management server as the workflow account verify/install SMLets.
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
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,
@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 ;)
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.
@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.
Thanks both.
Updated and still sits on the Get relationship:
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.
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,
Hi both,
Any ideas on this one? PSA activity just sits on In progress and Runbook still not moving.
TIA,
@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.