Home General Discussion

Retrieving AffectedUser for an Incident

JansiJansi Member IT Monkey ✭

Hi Team,

I am working on a SCSM self service portal. I need some help in knowing the set of SCSM commands with examples to retrieve the "AffectedUser" property value from an incident. I mean how to use get-SCSMrelationshipclass and get-SCSMrelationshipobject to retrieve the AffectedUser value. I have to know how to extract the FIle attachment in similar manner. I would appreciate if anyone can help me with the required and examples.

Thanking You,

Jansi

Best Answer

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
    Answer ✓

    You are super close. Per my 6th post in the series:

    We can use the PowerShell pipeline and say something to the effect of “Of all of the Related Objects on this Incident, get me the one whose Relationship ID equals the Relationship ID for the Affected User relationship class.” Now we see a single Relationship Object returned – the Incident and the Affected User. But what if we want just the single User object? As opposed to the Relationship Object of the Incident and the Affected User?

    $irClass = Get-SCSMClass -name "System.WorkItem.Incident$" -computername "mgmtserver01"
    $affectedUserRelClass = Get-SCSMRelationshipClass -Name "System.WorkItemAffectedUser$" -computername "mgmtserver01"
    $incident = Get-SCSMobject -class $irClass -filter "Name -eq 'IR1235'" -computername "mgmtserver01"
    $incidentAURelObject = Get-SCSMRelationshipObject -BySource $incident -computername "mgmtserver01" | Where-Object {$_.RelationshipId -eq $affectedUserRelClass.Id}
    Get-SCSMObject -id $incidentAURelObject.TargetObject.Id -computername "mgmtserver01"
    

Answers

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭

    hey there @Jansi

    I wrote a powershell blog series that covers this fairly extensively. The entire thread is below, but given where you are it's possible you may want to jump straight to Part 6.


  • JansiJansi Member IT Monkey ✭
    edited April 2021

    Hi Adam,

    Thanks a lot for the reply. I saw your post and tried the below set of commands to retrieve the "AffectedUser" for an incident. But it displays only the id which is in alphanumeric value along with the Full Name (empty). Please help me in retrieve the "AffectedUser" name (string value).

    $irClass = Get-SCSMClass -name "System.WorkItem.Incident$" -computername "idcscsm01t"
    $affectedUserRelClass = Get-SCSMRelationshipClass -Name "System.WorkItemAffectedUser$" -computername "idcscsm01t"
    $incident = Get-SCSMobject -class $irClass -filter "Name -eq 'IR3927'" -computername "idcscsm01t"
    Get-SCSMRelationshipObject -BySource $incident -computername "idcscsm01t" | Where-Object {$_.RelationshipId -eq $affectedUserRelClass.Id}
    
  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
    Answer ✓

    You are super close. Per my 6th post in the series:

    We can use the PowerShell pipeline and say something to the effect of “Of all of the Related Objects on this Incident, get me the one whose Relationship ID equals the Relationship ID for the Affected User relationship class.” Now we see a single Relationship Object returned – the Incident and the Affected User. But what if we want just the single User object? As opposed to the Relationship Object of the Incident and the Affected User?

    $irClass = Get-SCSMClass -name "System.WorkItem.Incident$" -computername "mgmtserver01"
    $affectedUserRelClass = Get-SCSMRelationshipClass -Name "System.WorkItemAffectedUser$" -computername "mgmtserver01"
    $incident = Get-SCSMobject -class $irClass -filter "Name -eq 'IR1235'" -computername "mgmtserver01"
    $incidentAURelObject = Get-SCSMRelationshipObject -BySource $incident -computername "mgmtserver01" | Where-Object {$_.RelationshipId -eq $affectedUserRelClass.Id}
    Get-SCSMObject -id $incidentAURelObject.TargetObject.Id -computername "mgmtserver01"
    
  • JansiJansi Member IT Monkey ✭

    Hi Adam,

    Thanks for the immediate response. You have made my day :)

    At present, I am going through all your powershell SMLets commands. It is very useful as i am very new to SMlets. I have a requirement where-in I have to integrate the incident modules and Service Request modules to the servicenow. Today i get some confidence that i can do this assignment.

    Thank you so so much Adam!

    Regards,

    -Jansi

Sign In or Register to comment.