Wednesday, January 25, 2012

AxoSoft OnTime SDK Creating an Incident, Worklog and Closing the Incident through PowerShell

clear
$incidentName="Management and Restructuring of OnTime Request System"
$incidentDescription="Re-did how releases stage/prod are handled"
$workTimeMinutes=30
$projectId=37
$worklogDescription="Moving Items in OnTime"
$durationMinutes=30
$workflowInitialId=161
$isClose=1
$finalWorkflowId=75

$securityToken="your guid goes here"
$UserId_karell=2
$TimeUnitTypeId_minutes=1
$workflowId=4

$incidentUrl="http://[your server url goes here]/ontimesdk/incidentservice.asmx"
$worklogUrl="http://[your server url goes here]/ontimesdk/worklogservice.asmx"
$typeUrl="http://[your server url goes here]/ontimesdk/typeservice.asmx"
$workflowUrl="http://[your server url goes here]/ontimesdk/workflowservice.asmx"
$customerUrl="http://[your server url goes here]/ontimesdk/customerservice.asmx"
$projectUrl="http://[your server url goes here]/ontimesdk/projectservice.asmx"

$onTimeServerIncident = New-WebServiceProxy $incidentUrl -Namespace incidents
$onTimeWorklogServer = New-WebServiceProxy $worklogUrl -Namespace worklogs
$onTimeTypeServer = New-WebServiceProxy $typeUrl -Namespace types
$onTimeWorkflow = New-WebServiceProxy $workflowUrl -Namespace workflows
$onTimeCustomer = New-WebServiceProxy $customerUrl -Namespace customers
$onTimeProject = New-WebServiceProxy $projectUrl -Namespace projects

$incidentHandler = New-Object incidents.IncidentHandler
$incident = New-Object incidents.incident
$worklogHandler = New-Object worklogs.WorkLogHandler
$worklog = New-Object worklogs.worklog
$typeHandler = New-Object types.TypeHandler
$workflowHandler = New-Object workflows.WorkflowHandler
$customerHandler = New-Object customers.CustomerHandler
$projectHandler = New-Object projects.ProjectHandler

#$dataset = $typeHandler.GetTimeUnitTypes($securityToken)
#$dataset = $workflowHandler.GetStepsByWorkflowId($securityToken,$workflowId)
#$dataset = $customerHandler.GetAllCustomerContacts($securityToken)
#$dataset = $projectHandler.GetAllProjects($securityToken)

$incident.Name=$incidentName
$incident.Description=$incidentDescription
$incident.ReportedDate=Get-Date
$incident.SeverityTypeId=0
$incident.ProjectId=$projectId
$incident.ReportedById=$UserId_karell
$incident.EstimatedDuration=$durationMinutes
$incident.DurationUnitTypeId=1
$incident.LastUpdatedById=$UserId_karell
$incident.RemainingDuration=$durationMinutes
$incident.RemainingUnitTypeId=1
$incident.DueDate=Get-Date
$incident.CreatedById=$UserId_karell
$incident.AssignedToId=$UserId_karell
$incident.PercentComplete=0
$incident.WorkflowStepId=$workflowInitialId

$resultIncidentId = $incidentHandler.AddIncident($securityToken,$incident)

$worklog.Description="Created Request"
$worklog.ItemType="Incident"
$worklog.UserId=$UserId_karell
$worklog.WorkDateTime=Get-Date
$worklog.ItemId=$resultIncidentId
$worklog.WorkDone=5
$worklog.WorkUnitTypeId=1
$worklog.WorkLogTypeId=4

$worklogResult = $worklogHandler.AddWorkLog($securityToken,$worklog)

$worklog.Description=$worklogDescription
$worklog.ItemType="Incident"
$worklog.UserId=$UserId_karell
$worklog.WorkDateTime=Get-Date
$worklog.ItemId=$resultIncidentId
$worklog.WorkDone=$workTimeMinutes
$worklog.WorkUnitTypeId=1
$worklog.WorkLogTypeId=4

$worklogResult = $worklogHandler.AddWorkLog($securityToken,$worklog)

$worklog.Description="Closing Request"
$worklog.ItemType="Incident"
$worklog.UserId=$UserId_karell
$worklog.WorkDateTime=Get-Date
$worklog.ItemId=$resultIncidentId
$worklog.WorkDone=5
$worklog.WorkUnitTypeId=1
$worklog.WorkLogTypeId=4

$worklogResult = $worklogHandler.AddWorkLog($securityToken,$worklog)

$incident = $incidentHandler.GetByIncidentId($securityToken,$resultIncidentId)
"Request created " + $incident.IncidentId + " - " + $incident.IncidentNumber

if ($isClose)
{
$incident.WorkflowStepId=$finalWorkflowId
$incident.Archived=$isClose
$incident.PercentComplete=100
$incident.RemainingDuration=0
$incident.ActualDuration=$workTimeMinutes
$incident.StartDate=Get-Date
$incident.CompletionDate=Get-Date

$result = $incidentHandler.UpdateIncident($securityToken,$incident)
"Closed and Archived Request"
}

No comments:

Post a Comment