PowerShell and ServiceNow API | Get variable values from sc_req_item / sc_item_option_mtom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 05:20 PM
Hi,
I am trying to get the Service Catalog (sc_item_option_mtom) variables using PowerShell.
Code that i am using works so far, i can get the value of the sc_item_option. but not sure how i can pull the value from the object.
$Global:ServiceTableWSDL = New-WebServiceProxy -uri https://myinstance.service-now.com/sc_item_option_mtom.do?WSDL —Credential $Credential
$Global:GetRecordsQuery = new-object ($NamesSpace + '.getRecords')
$GetRecordsQuery.request_item="MY REQEST ID"
$Global:EMPTickets = $ServiceTableWSDL.getRecords($GetRecordsQuery)
Write-Host "REached" $Global:EMPTickets.Count "Count"
foreach ($tree in $Global:EMPTickets) {
write-host $tree.sc_item_option
}
This all works fine and i am able to get the id of the sc_item_option. But not sure how i can get the variable name and value from this.
Do i have to make an additional calls to sc_item_option table. Since there are many variables it would mean multiple calls to get each variable and value. Please guide.
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 03:59 AM
Hi
If you tell the webservice to return display values, you should be able to get the name of the variable from the field called "item_option_new"
The value is in the "value" field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 03:02 PM
Hi Lars,
Thanks for your response. I am still not clear on how to use it in the powershell example that i have posted above. Sorry for this, i am just new and learning
I tried
$Global:ServiceTableWSDL = New-WebServiceProxy -uri https://myinstance.service-now.com/sc_item_option_mtom.do?WSDL —Credential $Credential
$Global:GetRecordsQuery = new-object ($NamesSpace + '.getRecords')
$GetRecordsQuery.request_item="MY REQEST ID"
$GetRecordsQuery.displayvalue="true"
$Global:EMPTickets = $ServiceTableWSDL.getRecords($GetRecordsQuery)
Write-Host "REached" $Global:EMPTickets.Count "Count"
foreach ($tree in $Global:EMPTickets) {
write-host $tree.sc_item_option
}
The property 'displayvalue' cannot be found on this object. Verify that the property exists and can be set.
From the web browser url i am doing something like this
or /api/now/table/sc_item_option_mtom?request_item=01824836db0fa200ec0a76c9bf961959&displayvalue=true
but i am still getting the same response. This is just the browser test. but powershell is also not working
<sc_item_option>
<value>78824836db0fa200ec0a76c9bf961957</value>
</sc_item_option>
UPDATE:
I changed the servicetableWSDL to
$Global:ServiceTableWSDL = New-WebServiceProxy -uri 'https://myinstance/sc_item_option_mtom.do?displayvalue=all&WSDL' —Credential $Credential
and now getting value for $tree.dv_sc_item_option which is again the SYS_id for linked table and
these ones are blank.
$tree.dv_sc_item_option.item_option_new or $tree.dv_sc_item_option.item_option_new.value or $tree.dv_sc_item_option.value