PowerShell and ServiceNow API | Get variable values from sc_req_item / sc_item_option_mtom

kunalmittal
Kilo Contributor

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

2 REPLIES 2

larstange
Mega Sage

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"



http://wiki.servicenow.com/index.php?title=Direct_Web_Services#Return_Display_Value_for_Reference_Va...



The value is in the "value" field


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


https://myinstance/api/now/table/sc_item_option_mtom?request_item=01824836db0fa200ec0a76c9bf961959&d...  



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>


<link>


https://myinstance/api/now/table/sc_item_option/78824836db0fa200ec0a76c9bf961957


</link>


<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