ServiceNow Ticket incident generator

Recently I have used the code below to create a ticket within my service now environment provided by Adam Driscoll.

I would like to change the default assignment group once the ticket is created.

Would $assignmentgroup = “groupname” work?
Is there a JSON object name (key value pair) that I would need to follow?

Happy New Year
And thank you for your time and patience.

$Dashboard = New-UDDashboard -Title “Report an Issue” -Content {

New-UDInput -Title "Report an Issue" -Endpoint {
    param(
        [Parameter(Mandatory)]
        [string]$Summary,

        [Parameter(Mandatory)]
        [string]$Description,

        [Parameter(Mandatory)]
        [ValidateSet("Software", "Hardware", "Phone")]
        [string]$Category,
        
        [Parameter(Mandatory)]
        [ValidateSet("Low - Inconvenience", "Medium - Work Impacted", "High - I cannot complete my tasks")]
        [string]$Priority
    )

    $ServiceNowIncidentData = @{
        short_description = $Summary
        description       = $Description
        contact_type      = "UniversalDashboard"
        category          = $Category
        priority          = "3"
    }

    # Service NOW Configuration
    # Set headers
    $GlobalHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $GlobalHeaders.Add('Accept', 'application/json')
    $GlobalHeaders.Add('Content-Type', 'application/json')

    #Note - migrate this to local creds, vault, or other method
    $user = 'user'
    $pass = 'password'

    # Build & Set Auth header
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
    $GlobalHeaders.Add('Authorization', ('Basic {0}' -f $base64AuthInfo))

    # Instance REST API - https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/task/t_GetStartedCreateInt.html
    $CreateIncidentURL = 'https://dev11111.service-now.com/api/now/table/incident'
           
    $PostResponse = Invoke-WebRequest -Headers $GlobalHeaders -Method "POST" -Uri $CreateIncidentURL -Body  ($ServiceNowIncidentData | ConvertTo-Json) -UseBasicParsing

    New-UDInputAction -Content {
        New-UDCard -Title "Incident: $(($PostResponse.Content | ConvertFrom-JSON).result.number) Created!" -Text "Your ticket for: ""$Summary"" has been submitted to the Service Desk!"
    }

} -Validate

}

Start-UDDashboard -Dashboard $Dashboard -Port 10000

Pinging @leeberg . He can probably help

Hi,
Add assignment_group = $yourassignmentgroup in
$ServiceNowIncidentData and it should work according to the docs.
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/reference/r_TableAPI-POST.html

See the curl examples.

1 Like

Yes! You can user the GUID of the assignment group enum or even the disaplyname:

assignment_group = "287ebd7da9fe198100f92cc8d1d2154e"

or

assignment_group = "Help Desk"

Works in my lab!

Please note that as you are testing - you may find limitations in what you can do with the ServiceNOW REST API. Once you hit this, you may want to consider utilizing “Business Rules”

https://docs.servicenow.com/bundle/madrid-application-development/page/script/business-rules/concept/c_BusinessRules.html

Also, like @BoSen29 suggested the docs for the rest api can help A LOT!

1 Like

Thank you so much everyone for all your help.
I will try each suggestion and keep everyone updated.
Your help is greatly appreciated.
Happy New Year again!

2 Likes

Happy New Year again.

All suggestions worked beautifully!

Thanks everyone’s help I even found the “assigned_to” key value pair object so a ticket can be assigned straight to a specific user.

Thanks every one for their help.

The next step is to setup a landing page where server owners and managers can decomm there servers and have service now ticket be generated and leverage a MID server to remove servers from SolarWinds , veeam backup , VMware delete from disk and delete the Active directory object.

I hope to update this site with my successful code that anyone can use.

Below is the code that went with to assign a ticket to a specific group and user if needed:

Import-Module UniversalDashboard
$Dashboard = New-UDDashboard -Title “Report an Issue” -Content {

New-UDInput -Title "Report an Issue" -Endpoint {
    param(
        [Parameter(Mandatory)]
        [string]$Summary,

        [Parameter(Mandatory)]
        [string]$Description,

        [Parameter(Mandatory)]
        [ValidateSet("Software", "Hardware", "Phone")]
        [string]$Category,
        
        [Parameter(Mandatory)]
        [ValidateSet("Low - Inconvenience", "Medium - Work Impacted", "High - I cannot complete my tasks")]
        [string]$Priority
    )

    $ServiceNowIncidentData = @{
        short_description = $Summary
        description       = $Description
        contact_type      = "UniversalDashboard"
        category          = $Category
        priority          = "3"
        assignment_group = "Network Engineering"
        assigned_to      = "User1"
    }

    # Service NOW Configuration
    # Set headers
    $GlobalHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $GlobalHeaders.Add('Accept', 'application/json')
    $GlobalHeaders.Add('Content-Type', 'application/json')

    #Note - migrate this to local creds, vault, or other method
    $user = 'user'
    $pass = 'pass'

    # Build & Set Auth header
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
    $GlobalHeaders.Add('Authorization', ('Basic {0}' -f $base64AuthInfo))

    # Instance REST API - https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/task/t_GetStartedCreateInt.html
    $CreateIncidentURL = 'https://.service-now.com/api/now/table/incident'
           
    $PostResponse = Invoke-WebRequest -Headers $GlobalHeaders -Method "POST" -Uri $CreateIncidentURL -Body  ($ServiceNowIncidentData | ConvertTo-Json) -UseBasicParsing

    New-UDInputAction -Content {
        New-UDCard -Title "Incident: $(($PostResponse.Content | ConvertFrom-JSON).result.number) Created!" -Text "Your ticket for: ""$Summary"" has been submitted to the Service Desk!"
    }

} -Validate

}

Start-UDDashboard -Dashboard $Dashboard -Port 10000

1 Like