locked
ReviewerID and Displayname showing up as numbers RRS feed

  • Question

  • I have started a new script to set Change request status to approved if the review activity is completed, and approved.

    $RAClass = get-SCSMClass -name System.WorkItem.Activity.ReviewActivity$
    $CRClass = get-scsmclass -name System.WorkItem.ChangeRequest$
    $RAobj = Get-SCSMObject -Class $RAClass -Filter "ID -eq $RA_ID" 
    [string]$CRdisplayname = (Get-SCSMRelationshipObject -ByTarget $RAobj).sourceobject.displayname
    $CRobj = Get-SCSMObject -Class $CRClass -Filter "Displayname -eq $CRdisplayname"
    
    Next line I am working on
    
    Get-SCSMRelatedObject -SMObject $RAobj
    
    Results:
    
    ClassName                                                                 DisplayName                                                              LastModified          
    ---------                                                                 -----------                                                              ------------          
    System.Reviewer                                                           332                                                                      12/10/2012 10:48:28 PM
    System.Reviewer                                                           419                                                                      12/4/2012 1:35:35 PM  
    System.Reviewer                                                           420                                                                      12/4/2012 1:35:35 PM  

    Displayname is a number?  Any ideas on why?  Is there somewhere I can correlate them to thier real names?

    Also, I am looking to determine the best way to get the decision porperty on each of these review activites.  I  only need one approval, and there will only typically be 2 approvers.  So I have the RA set to 50% for "completeness" but just because 50% have voted, that does not mean they approved it.  I need to make sure that once the RA is completed that it is also approved.   Then I will set the status on the parent CR to approved.

    Any ideas?


    Joshua Fuente



    • Edited by NachoScript Tuesday, December 11, 2012 2:12 PM
    Tuesday, December 11, 2012 2:11 PM

Answers

  • Users are not directly related to review activities. Users are first related to "Reviewer" objects. Those Reviewer objects are then related to review activities. This intermediate "Reviewer" object maintains the vote, date voted, and other properties.

    So, in order to get the reviewer's user record, use

    Get-SCRelationshipInstance -SourceInstance (Get-SCSMRelatedObject -SMObject $RAobj)

    This returns an array of EnterpriseManagementRelationshipObject (I call them EMROs). The SourceObject of one of those EMROs is the Reviewer object (the number you were getting earlier). The TargetObject is the User object (which contains the name of the user, etc). For completeness, you should also verify the relationship type in the EMRO is "System.ReviewerIsUser" using Get-SCRelationship and the .RelationshipId property.

    As for voting (unless something changed in SM2012), if someone votes against the review activity, the activity will fail and the entire change request will be set to failed. If the approval threshold is met, the review activity will be set to completed and the next activity in the list will be set in progress. So, really all you should need to do is wait for the review activity to complete, then set your CR to approved. But, if you want the decision for each reviewer, look at the .Decision property on the Reviewer object.

    For example:

    Get-SCSMRelatedObject -SMObject $RAobj | %{$_.Decision}

    or, to tie the reviewer's decision and the reviewer together:

    Get-SCSMRelatedObject -SMObject $RAobj | %{$_.SourceObject.Values[1].ToString() + " " + $_.TargetObject.displayname}

    Note that I used .Values[1]..which is probably the wrong way to get the Decision property. I don't use the cmdlets very often, so there's probably a better way to get it.
    • Edited by Aaron Croasmun Tuesday, December 11, 2012 2:58 PM
    • Marked as answer by NachoScript Tuesday, December 11, 2012 3:59 PM
    Tuesday, December 11, 2012 2:56 PM

All replies

  • Users are not directly related to review activities. Users are first related to "Reviewer" objects. Those Reviewer objects are then related to review activities. This intermediate "Reviewer" object maintains the vote, date voted, and other properties.

    So, in order to get the reviewer's user record, use

    Get-SCRelationshipInstance -SourceInstance (Get-SCSMRelatedObject -SMObject $RAobj)

    This returns an array of EnterpriseManagementRelationshipObject (I call them EMROs). The SourceObject of one of those EMROs is the Reviewer object (the number you were getting earlier). The TargetObject is the User object (which contains the name of the user, etc). For completeness, you should also verify the relationship type in the EMRO is "System.ReviewerIsUser" using Get-SCRelationship and the .RelationshipId property.

    As for voting (unless something changed in SM2012), if someone votes against the review activity, the activity will fail and the entire change request will be set to failed. If the approval threshold is met, the review activity will be set to completed and the next activity in the list will be set in progress. So, really all you should need to do is wait for the review activity to complete, then set your CR to approved. But, if you want the decision for each reviewer, look at the .Decision property on the Reviewer object.

    For example:

    Get-SCSMRelatedObject -SMObject $RAobj | %{$_.Decision}

    or, to tie the reviewer's decision and the reviewer together:

    Get-SCSMRelatedObject -SMObject $RAobj | %{$_.SourceObject.Values[1].ToString() + " " + $_.TargetObject.displayname}

    Note that I used .Values[1]..which is probably the wrong way to get the Decision property. I don't use the cmdlets very often, so there's probably a better way to get it.
    • Edited by Aaron Croasmun Tuesday, December 11, 2012 2:58 PM
    • Marked as answer by NachoScript Tuesday, December 11, 2012 3:59 PM
    Tuesday, December 11, 2012 2:56 PM
  • Awesome!! Thanks, that makes this a lot easier!  (finally default behavior that makes its easier)

    I think I can handle it from here, when I finish the script, I will post it.


    Joshua Fuente

    Tuesday, December 11, 2012 3:59 PM