Use Powershell to update a Ticket

Arvind17
Kilo Contributor

Hi,

I am working on a PowerShell based script to update a ticket in ServiceNow. The process I would be following is: - 

Retrieve a Service Now Incident

Download it in XML/JSON format

Update the fields such as Work Log/Close or Reopen a Ticket

and then Use the PowerShell to post the Update to Service Now.

I am able to get a ticket but posting an update to ServiceNow seems to be whol;e different ballgame. The code I have so far is as below: - 

if(!$ServiceNowCreds){

    $ServiceNowCreds = Get-Credential

}

$uri = 'https://dev22777.service-now.com/api/now/table/{table_name}/{sys_id}

#sys_id=df01d2434f41130095d22ed18110c704'

$Body = "<request><entry>

        <work_notes>Issue is resolved</work_notes>

        </entry></request>"

$result = Invoke-RestMethod -Method Patch -Uri $uri -Credential $ServiceNowCreds -Headers $headers -Body $Body -ContentType "application/json"

 Request your help/assistance in this regard.

3 REPLIES 3

Mike Patel
Tera Sage

I don't see {table_name} variable value anywhere in code.

Mike, Thanks for the same. But could you please guide me on the table name or nanamesved to be used in the code.. We have just now started with the learning and building solutions for ServiceNow. Any assistance would be great. Arvind

If you are trying to update incident than table name needs to be incident.

like https://dev22777.service-now.com/api/now/table/incident/{sys_id}