Trying to get the parent CR of a review activity...

Dec 11, 2012 at 2:00 AM

Not having much luck with this one, any help much appreciated!

 

$RA_ID = "RA612"

$RAClass = get-SCSMClass -name System.WorkItem.Activity.ReviewActivity$

$ParentCR = Get-SCSMRelationshipObject -Target $RAClass | ?{$_.TargetObject -match $RA_ID}

returns this error,

Get-SCSMRelationshipObject : Object reference not set to an instance of an object.
At line:12 char:39
+ $ParentCR = Get-SCSMRelationshipObject <<<<  -Target $RAClass | ?{$_.TargetObject -match $RA_ID}
    + CategoryInfo          : InvalidOperation: (SMLets.GetSCSMRelationshipObjectCommand:GetSCSMRelationshipObjectCommand) [Get-SCSMRelationshipObject], NullReferenceEx
   ception
    + FullyQualifiedErrorId : RelationshipQuery,SMLets.GetSCSMRelationshipObjectCommand

This is where is it seems to go wrong,

Get-SCSMRelationshipObject -Target $RAClass

PS H:\> Get-SCSMRelationshipObject -Target $RAClass
Get-SCSMRelationshipObject : Object reference not set to an instance of an object.
At line:1 char:27
+ Get-SCSMRelationshipObject <<<<  -Target $RAClass
    + CategoryInfo          : InvalidOperation: (SMLets.GetSCSMRelationshipObjectCommand:GetSCSMRelationshipObjectCommand) [Get-SCSMRelationshipObject], NullReferenceEx
   ception
    + FullyQualifiedErrorId : RelationshipQuery,SMLets.GetSCSMRelationshipObjectCommand

Apr 21, 2013 at 5:50 PM
Try this to see if it works for you.
$SCSMServer = "localhost"
$RA = "RA12345"
$ParentRequestRelationshipID = "2da498be-0485-b2b2-d520-6ebd1698e61b"
$ReviewActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ReviewActivity$  -ComputerName $SCSMServer) -ComputerName $SCSMServer -Filter "ID -eq $RA"

$RelatedParentRequest = (Get-SCSMRelationshipObject -ComputerName $SCSMServer -ByTarget $ReviewActivity  | ?{$_.RelationshipID -eq $ParentRequestRelationshipID -and $_.IsDeleted -eq $False}) 
Ray
May 24, 2013 at 8:56 PM
Hi Ray - Is the parentrequestrelationshipID something specific to your setup?
May 26, 2013 at 7:59 PM
No, this should be the same in your environment as its the same in my 3 environments and they are separate installs, not clones.

Also, if you have nested a activity this wont work since it will return the parent which maybe a Parallel Activity or something else. I have a new script block which will hunt up the parents until it gets to the SR or CR. I'll post it on Monday.

Ray
Jun 6, 2013 at 9:43 PM
This is a block of code I use since I have many activities nested in parallel activities and I want to make sure the parent is actually the SR or CR.
$SCSMServer = "localhost"
$RA = "RA12345"
$ParentRequestRelationshipID = "2da498be-0485-b2b2-d520-6ebd1698e61b"
$ReviewActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ReviewActivity$  -ComputerName $SCSMServer) -ComputerName $SCSMServer -Filter "ID -eq $RA"

$RelatedParentRequest = (Get-SCSMRelationshipObject -ComputerName $SCSMServer -ByTarget $ReviewActivity  | ?{$_.RelationshipID -eq $ParentRequestRelationshipID -and $_.IsDeleted -eq $False}) 

# Check to see if the parent is the SR or CR
If (-not($RelatedParentRequest.SourceObject.Name -like "CR*" -or $RelatedParentRequest.SourceObject.Name -like "SR*"))
    {
        DO {
                $ParentActivity = Get-SCSMObject -Id $RelatedParentRequest.SourceObject.Id -ComputerName $SCSMServer
                $RelatedParentRequest = (Get-SCSMRelationshipObject -ComputerName $SCSMServer -ByTarget $ParentActivity | ?{$_.RelationshipID -eq $ParentRequestRelationshipID -and $_.IsDeleted -eq $False}) 
                $count += 1
            } Until ($RelatedParentRequest.SourceObject.Name -like "CR*" -or $RelatedParentRequest.SourceObject.Name -like "SR*" -or $count -ige 10)
    }