Skip to content

Using a template to create New CWMTicketTask

Chris Taylor edited this page Apr 16, 2021 · 8 revisions

We will start by pulling up the New-CWMTemplate and, opening up the API documentation for the endpoint we are working with.

We create a new file New-CWMTicketTask.ps1 in the appropriate directory and, update the function name to match.

Update the function with the version of the API you are using. It can be found at the top of the docs.

We then want to update the to match the endpoint we are using.

New endpoints are the most complicated as you need to handle ALL the parameters listed in the schema.

You will want to type all your inputs appropriately

  • integer - [int]
  • string - [string]
  • boolean - [boolean]
  • any 'reference' - [hashtable]
  • enum - create a validation set

Set all required parameters as mandatory.

We don't have any parameters we need to skip so we can remove that.

function New-CWMTicketTask {
    # 2020.4
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'Used by sub-function')]
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
    param(
        [Parameter(Mandatory=$true)]
        [Alias('ticketId')]
        [int]$parentId,
        [int]$id,
        [string]$notes,
        [boolean]$closedFlag,
        [int]$priority,
        [hastable]$schedule,
        [hashtable]$code,
        [string]$resolution,
        [ValidateSet('Transfer', 'Delete', 'Done')]
        $childScheduleAction,
        [int]$childTicketId,
        [hashtable]$_info
    )

    $Endpoint = "/service/tickets/$($parentId)/tasks"
    return Invoke-CWMNewMaster -Arguments $PsBoundParameters -Endpoint $Endpoint
}