Closed AdhocAdam closed 6 years ago
This new function is the result of the combination of the previous 4 functions for Add-IncidentComment, Add-ServiceRequestComment, Add-ProblemComment, and Add-ChangeRequest comment. As such it should be capable of handling all cases for working with an Incident, Problem, Service, or Change Request's Action Log by simply passing the necessary parameters.
This function can also be used independently of the connector by simply removing "@scsmMGMTParams" as well as using a custom Change Request Type Projection in the event the Cireson SCSM Portal is not used.
function Add-ActionLogEntry {
param (
[parameter(Mandatory=$true, Position=0)]
$WIObject,
[parameter(Mandatory=$true, Position=1)]
[ValidateSet("Assign","AnalystComment","Closed","Escalated","EmailSent","EndUserComment","FileAttached","FileDeleted","Reactivate","Resolved","TemplateApplied")]
[string] $Action,
[parameter(Mandatory=$true, Position=2)]
[string] $Comment,
[parameter(Mandatory=$true, Position=3)]
[string] $EnteredBy,
[parameter(Mandatory=$false, Position=4)]
[Nullable[boolean]] $IsPrivate = $false
)
#Choose the Action Log Entry to be created. Depending on the Action Log being used, the $propDescriptionComment Property could be either Comment or Description.
switch ($Action)
{
Assign {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.RecordAssigned"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
AnalystComment {$CommentClass = "System.WorkItem.TroubleTicket.AnalystCommentLog"; $propDescriptionComment = "Comment"}
Closed {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.RecordClosed"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
Escalated {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.RecordEscalated"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
EmailSent {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.EmailSent"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
EndUserComment {$CommentClass = "System.WorkItem.TroubleTicket.UserCommentLog"; $propDescriptionComment = "Comment"}
FileAttached {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.FileAttached"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
FileDeleted {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.FileDeleted"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
Reactivate {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.RecordReopened"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
Resolved {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.RecordResolved"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
TemplateApplied {$CommentClass = "System.WorkItem.TroubleTicket.ActionLog"; $ActionType = "System.WorkItem.ActionLogEnum.TemplateApplied"; $ActionEnum = get-scsmenumeration $ActionType @scsmMGMTParams; $propDescriptionComment = "Description"}
}
#Alias on Type Projection for Service Requests and Problem and are singular, whereas Incident and Change Request are plural. Update $CommentClassName
if (($WIObject.ClassName -eq "System.WorkItem.Problem") -or ($WIObject.ClassName -eq "System.WorkItem.ServiceRequest")) {$CommentClassName = "ActionLog"} else {$CommentClassName = "ActionLogs"}
#Analyst and End User Comments Classes have different Names based on the Work Item class
if ($Action -eq "AnalystComment")
{
switch ($WIObject.ClassName)
{
"System.WorkItem.Incident" {$CommentClassName = "AnalystComments"}
"System.WorkItem.ServiceRequest" {$CommentClassName = "AnalystCommentLog"}
"System.WorkItem.Problem" {$CommentClassName = "Comment"}
"System.WorkItem.ChangeRequest" {$CommentClassName = "AnalystComments"}
}
}
if ($Action -eq "EndUserComment")
{
switch ($WIObject.ClassName)
{
"System.WorkItem.Incident" {$CommentClassName = "UserComments"}
"System.WorkItem.ServiceRequest" {$CommentClassName = "EndUserCommentLog"}
"System.WorkItem.Problem" {$CommentClass = "System.WorkItem.TroubleTicket.AnalystCommentLog"; $CommentClassName = "Comment"}
"System.WorkItem.ChangeRequest" {$CommentClassName = "UserComments"}
}
}
# Generate a new GUID for the entry
$NewGUID = ([guid]::NewGuid()).ToString()
# Create the object projection with properties
$Projection = @{__CLASS = "$($WIObject.ClassName)";
__SEED = $WIObject;
$CommentClassName = @{__CLASS = $CommentClass;
__OBJECT = @{Id = $NewGUID;
DisplayName = $NewGUID;
ActionType = $ActionType;
$propDescriptionComment = $Comment;
Title = "$($ActionEnum.DisplayName)";
EnteredBy = $EnteredBy;
EnteredDate = (Get-Date).ToUniversalTime();
IsPrivate = $IsPrivate;
}
}
}
#create the projection based on the work item class
switch ($WIObject.ClassName)
{
"System.WorkItem.Incident" {New-SCSMObjectProjection -Type "System.WorkItem.IncidentPortalProjection" -Projection $Projection @scsmMGMTParams}
"System.WorkItem.ServiceRequest" {New-SCSMObjectProjection -Type "System.WorkItem.ServiceRequestProjection" -Projection $Projection @scsmMGMTParams}
"System.WorkItem.Problem" {New-SCSMObjectProjection -Type "System.WorkItem.Problem.ProjectionType" -Projection $Projection @scsmMGMTParams}
"System.WorkItem.ChangeRequest" {New-SCSMObjectProjection -Type "Cireson.ChangeRequest.ViewModel" -Projection $Projection @scsmMGMTParams}
}
}
Brilliant!
In order to best address the needs of #48, #60, #61, future requests within this area, as well as lead to a better Action Log on Work Items. This optimization seeks to combine all of the individual ActionLog functions into a single function that can handle any type of entry across Incidents, Problems, Service Requests, and Change Requests.
For example, calling the function should allow the ability to leave an End User Comment, Analyst Comment, as well as add entries that mimic console tasks such as Resolve, Reactivate, etc. In doing so, when these keywords across the Work Items are triggered they would invoke said entry in the Action Log. Thereby promoting consistency within the Action Log regardless of using the Console, Cireson Portal, or this - the SMLets Exchange Connector.
This requires not only a wholly new function (that is essentially all 4 of them thrown into 1), but also an update to all 19 calls of the previous 4 throughout the Update-WorkItem function.