Getting variable field text values through the API

Jacob53
Kilo Explorer

Good Afternoon,

I'm new to ServiceNow & the forums, so hopefully i'm posting this in the right area.

I'm using PowerShell with Invoke-WebRequest calls to pull and process certain tickets in ServiceNow, and I've run into something of a snag. When I pull a ticket using a call like this, I get what appears to be a limited return of variables.

 

$searchdata = Invoke-WebRequest -Method GET -Uri https://{myInstance}.service-now.com/api/now/table/sc_req_item/{ticketID} -Headers $snheaders
$searchdata = $searchdata.content | ConvertFrom-Json
$data = $searchdata.result

Within the $data object, I see returned variable values such as description, sys_created_by, and sys_updated_by, but there are other variables listed in the ticket that do not appear to be returned. The variables that are not returned are located at the bottom of the ticket in an area called variables. 

With some trial & error, I found that I could get the ID of the variable field with a call like this.

 

$searchdata = Invoke-WebRequest -Method GET -Uri https://{myInstance}.service-now.com/api/now/table/sc_req_item/{ticketID}?sysparm_fields=variables.{variableName}
$searchdata = $searchticket.content | ConvertFrom-Json
$data = $searchdata.result.{variables.variableName}

So to sum up, I’m looking for a way to get the actual text value from variable fields that are not returned with the standard ticket return.

Hope that makes sense, and thanks in advance for any insight that can be offered. 

 

2 REPLIES 2

Jacob53
Kilo Explorer

Sorry for the bad URL formatting, there wasn't a code option for PowerShell...

Danny Sun
Tera Guru

Thanks for the insights. I can get the RITM variable with sysparm_fields=variables.{variableName} from table API.

 

Regards,

Danny