Adding comments to SRs

Apr 8, 2013 at 2:44 PM
Hi Jim,

I'm looking into a way of adding a comment for a Service Request through PowerShell... and getting the membership error.

I've reviewed the example that Travis posted regarding creating an incident and including one comment by using a projection, but what's the alternative when you already have a work item and you just want to add a new comment to the action log via PowerShell?

Thanks!

German
Developer
Apr 8, 2013 at 6:29 PM
I've been out of the SM team for about 16 months, so I'm totally out of the loop here. I'm going off of some pretty old memories, but you should be able to create a new instance of a comment and then create a new relationship which connects the work item with the comment (I thought there was a script which helped with this, but I could be wrong about that - or it could be about incidents. Which means you need to track down the right relationship object.

sorry i'm not more help

jim
Apr 9, 2013 at 1:14 AM
Thanks, Jim! You gave me some hints...
Sorry to hear you're out of the SM team... :(

I'll share my findings with the rest in case you're looking for this:
function Add-SRComment {
    param (
            [parameter(Mandatory=$true,Position=0)][Alias('SRObject')]$pSRObject,
            [parameter(Mandatory=$true,Position=1)][Alias('Comment')][String]$pComment,
            [parameter(Mandatory=$true,Position=2)][Alias('EnteredBy')][String]$pEnteredBy
          )
    $NewGUID = ([guid]::NewGuid()).ToString()
    $Projection = @{__CLASS = "System.WorkItem.ServiceRequest";
                    __SEED = $pSRObject;
                    AnalystCommentLog = @{__CLASS = "System.WorkItem.TroubleTicket.AnalystCommentLog";
                                          __OBJECT = @{Id = $NewGUID;
                                                       DisplayName = $NewGUID;
                                                       Comment = $pComment;
                                                       EnteredBy  = $pEnteredBy;
                                                       EnteredDate = (Get-Date).ToUniversalTime();
                                                       IsPrivate = $false
                                                      }
                                         }
                   }
    New-SCSMObjectProjection -Type "System.WorkItem.ServiceRequestProjection" -Projection $Projection
}


Add-SRComment -SRObject $SR -Comment "This is a test" -EnteredBy "Doe, John"
Developer
Apr 9, 2013 at 4:11 PM
from what I can remember :) that looks good. I am a little surprised by the need to create a new projection rather than just create a new relationship