Pergunta

I'm working on a C# program that retrieves data from a ServiceNow database and converts that data into C# .NET objects. I'm using the JSON Web Service to return my data in JSON format.

What I want to achieve is as follows: If there is a relational mapping between a value (for example: I have a table called Company, where CEO is not a TEXT field but an sys_id to a Employee Table) I want to be able to output that data not with an sys_id (or just displaying the name property by using the 'displayvariable' parameter) but by an object displayed in JSON.

This means that the value of a property should be an object in JSON instead of just a single value.

A few examples:

// I don't want the JSON like this
{"Company":{"CEO":"b181e841c9212c008aeb36850331fab2"}}

// Or by displaying the name of the sys_id table
{"Company":{"CEO":"James Henderson" }}

// I want the data as follows, so I can have all the data I need inside a single JSON record.
{"Company":{"CEO":{"name":"James Henderson", "age":34, "sex":"male", "office":"SBN Left Floor 23"}}}

From reading the documentation I couldn't find anything in the JSON Web Service that allowed me to display the information like this nor find any other alternative. It should have something to do with joining the tables and displaying it all in the right format.

Foi útil?

Solução

I have been using SNC for almost three years and have not found you can automatically join tables in a web service. Your best option would be to use a scripted web service which possibly takes a query parameter and table parameter. Then you can json serialized your result as you see fit.

Or, another option would be to generate a new processor that will traverse the GlideRecord object. The ?JSON parameter you pass in to the URL is merely a flag to pass your request to a particular processor. Unfortunately the OOB one I believe is a Java class not a JS script, so you would need to write a script much like I mentioned earlier to traverse the object path serializing the object graph as far down as your want to go.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top