auto insert current user
Can someone help me edit this entry so that the userpicker automatically inserts the current user into the assigned to field.
{ DataType: "UserPicker", PropertyDisplayName: "AssignedTo", PropertyName: "AssignedWorkItem", Required: false, },
Best Answer
-
Justin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
I like the ideas that were presented in this thread by @Gerhard_Goossens.
I wrote this powershell that does the same thing.
param($CrID)
$crClass = Get-SCSMClass -name System.WorkItem.ChangeRequest$
$thisCR = Get-SCSMObject -id $CrID
Write-Output "Got CR: $($thisCR.Id)"
$assignedUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
$createdByRelClass = Get-SCSMRelationshipClass -Name System.WorkItemCreatedByUser
$createdRelationship = Get-SCSMRelationshipObject -BySource $thisCR | ?{$_.relationshipid -eq $createdByRelClass.id -and $_.sourceobject.classname -eq $crClass.Name}
$createdUser = Get-SCSMObject -id $createdRelationship.TargetObject.Id\
Write-output "Assigning to $($createdUser.displayname)"
New-SCSMRelationshipObject -Relationship $assignedUserRel -Source $thisCR -Target $createdUser -Bulk
I added it to a Powershell activity script and created a new Powershell Activity template using that script and I mapped the Parent Base Id to the CRID parameter in the Powershell Activity Template.
1
Answers
@alex_kokin - using the form definition to set the Assigned User is not possible. What are you ultimately trying to accomplish? Do you want any analyst that views the ticket to become the assigned analyst?
@Justin_Workman I built a ARO for Change requests but I need to either add a assign to field for the creator to fill in or have it auto assign to the creator of the change request.
@alex_kokin - You will need some kind of automation like an Orchestartor Runbook or Powrshell Activity in the activity chain in the CR. Do you use Orchestrator?
@Justin_Workman not at all...
@alex_kokin - In that case you might want to use Powershell Activity.
@Justin_Workman do you by chance have any scripts I may work with?
I like the ideas that were presented in this thread by @Gerhard_Goossens.
I wrote this powershell that does the same thing.
param($CrID)
$crClass = Get-SCSMClass -name System.WorkItem.ChangeRequest$
$thisCR = Get-SCSMObject -id $CrID
Write-Output "Got CR: $($thisCR.Id)"
$assignedUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
$createdByRelClass = Get-SCSMRelationshipClass -Name System.WorkItemCreatedByUser
$createdRelationship = Get-SCSMRelationshipObject -BySource $thisCR | ?{$_.relationshipid -eq $createdByRelClass.id -and $_.sourceobject.classname -eq $crClass.Name}
$createdUser = Get-SCSMObject -id $createdRelationship.TargetObject.Id\
Write-output "Assigning to $($createdUser.displayname)"
New-SCSMRelationshipObject -Relationship $assignedUserRel -Source $thisCR -Target $createdUser -Bulk
I added it to a Powershell activity script and created a new Powershell Activity template using that script and I mapped the Parent Base Id to the CRID parameter in the Powershell Activity Template.