Adding comments to SRs

Apr 8, 2013 at 3: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?


Apr 8, 2013 at 7: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

Apr 9, 2013 at 2: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 (
    $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"
Apr 9, 2013 at 5: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