How to create a change task using powershell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2020 10:17 AM
Hi Team,
I'm trying to create a change task using a powershell script. I was already successful for the change record creation, but when I try to create a change task nothing happens.
$ChgNumber='CHG0127576'
$Sys_ID='2230b72b1b4bdc106f662f876e4bcb53' #this is the sysid of the change record
$Uri1 = "https://nameofcustomer.service-now.com/api/now/table/task"
# Specify HTTP Method
$Method1 = "POST"
# Specify Request Body
$BodyTask = @{
priority = "3 - Medium"
assigned_to = "Name of the assignee"
u_task_type = "Implementation"
u_vendor = "Vendor_CORP"
assignment_group = "VENDOR-QUEUE"
short_description = "Implementation - $ChgNumber - Execute this task before"
description = "Long Description Long Description"
work_notes = "Change Created to Vendor_Corp"
}
$BodyJson_Task = $BodyTask | ConvertTo-Json
$Response1 = Invoke-WebRequest -Headers $header -Method $Method1 -Uri $Uri1 -Body $BodyJson_Task -ContentType "application/json"
$JsonPUT1 = $Response1 | ConvertFrom-Json
$PUTObject1 = $JsonPUT1.result
$Response1 = Invoke-WebRequest -Credential $SNowCreds -Headers $Header -Method 'GET' -Uri $Uri1 -ContentType "application/json"
I received the response below
StatusCode : 201
StatusDescription : Created
Content : {}
RawContent : HTTP/1.1 201 Created
X-Is-Logged-In: true
X-Transaction-ID: 40dee30d1bdf
Transfer-Encoding: chunked
Date: Tue, 15 Sep 2020 16:31:01 GMT
Location: https://nameofcustomer.service-now.com/api/now/tab...
Headers : {[X-Is-Logged-In, true], [X-Transaction-ID, 40dee30d1bdf], [Transfer-Encoding, chunked], [Date, Tue, 15 Sep 2020 16:31:01 GMT]...}
RawContentLength : 0
But when I look the tasks for the change, no one was created. Any Help Please.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 06:53 PM
Hi,
Along with the 201 and response headers, you should also receive a response body which details the created record. As you're not defining the sys_class_name in your body, you're likely creating tasks directly on the task table rather than the child change_task table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2020 09:40 AM
Hi, Checking in on whether my reply resolved your query? If my reply helped with your issue please mark helpful ???? and correct if your issue is now resolved. ✅
By doing so you help other community members find resolved questions which may relate to an issue they're having.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 04:49 AM
Hi Kieran,
Thanks for replying back.
I included the fields sys_class_name, change_request and the sys_id. On the URL I also changed to $Uri1 = "https://<<nameofinstance>>.service-now.com/api/now/table/sc_task"
$BodyTask = @{
sys_class_name = "change_task"
change_request = 'CHG0127581'
sys_id = '7b1a8e801bab94d06f662f876e4bcb64'
priority = "3 - Medium"
assigned_to = "Name of the assignee"
u_task_type = "Implementation"
u_vendor = "Vendor_CORP"
assignment_group = "VENDOR-QUEUE"
short_description = "Implementation - $ChgNumber - Execute this task before"
description = "Long Description Long Description"
work_notes = "Change Created to Vendor_Corp"
}
And now I got this message (403) Forbidden. Since I was able to create a change record, I suppose my authentication it is correct. I believe I don't have permission to modify the table for changes tasks.
Am I doing this right?