Using the WorkXpress API: LookupData
Last week I introduced you to the WorkXpress API. If you have not read it already you should do so before reading this post. Once you have a basic understanding of what it is and how it works, it's time to start diving into the API.
This post will cover how to read data from a WorkXpress Application using the LookupData function. LookupData allows you to retrieve values from items and relationships. If you know the item or relation id, you can retrieve the data directly from the Item. If you don't have an id, you can use a map to search for items and relationships. The WorkXpress API allows you to make many LookupData requests in the same function call using data sets.
Request XML
First, let's get an understanding of how the request XML should be formed.
| Element | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| /wxRequest | The root node for all request documents. | ||||||||||||
| /wxRequest/dataSet |
Contains a single LookupData request. You may have as many data sets as you would like. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ items |
Root node for the items that should be retrieved. | ||||||||||||
| /wxRequest/dataSet/ items/item |
A single item to be retrieved. There is no limit to the number of item nodes allowed in a data set. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ items/map |
The root node for a map definition. | ||||||||||||
| /wxRequest/dataSet/ items/map/definition |
The actual definition for a map. The map XML must have its HTML entities encoded. | ||||||||||||
| /wxRequest/dataSet/fields | Root node for the fields that should be read from the items that were found in the items node. | ||||||||||||
| /wxRequest/dataSet/ fields/field |
A single field to read data from. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ fields/field/ format |
Display format for the defined field. Display formats will be explained in a later post. For now we will pull the "text" value of all fields. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ relations |
Root node for relations that should be looked up from the items found in the items node. | ||||||||||||
| /wxRequest/dataSet/ relations/relation |
Root node for relations that should be looked up from the items found in the items node. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields |
Root node for the fields that should be read from the relations that were found in the items node. | ||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field |
A single field to read data from. Attributes:
|
||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field/ format |
Display format for the defined field. Display formats will be explained in a later post. For now we will pull the "text" value of all fields. Attributes:
|
Response XML
Now let's get an understanding of how the response XML will be formed.
| Element | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| /wxResponse | The root node for all response documents. | ||||||||||||||||||||||||
| /wxRequest/callStatus |
The status of the SOAP call as it was processed by WorkXpress. Attributes:
|
||||||||||||||||||||||||
| /wxResponse/compatibilityLevel | The version of the API that was used to process the request. | ||||||||||||||||||||||||
| /wxRequest/dataSet |
One data set is returned for each data set in the request document. Attributes:
|
||||||||||||||||||||||||
| /wxRequest/dataSet/ item |
A single item found based on the items defined in the request. Attributes:
|
||||||||||||||||||||||||
| /wxRequest/dataSet/ item/field |
A single field that was retrieved based on the request. Attributes:
|
||||||||||||||||||||||||
| /wxRequest/dataSet/ item/field/ value |
The value of the current field, in the format defined in the request. | ||||||||||||||||||||||||
| /wxRequest/dataSet/ item/relation |
Contains the data for a single relation that was found. Attributes:
|
||||||||||||||||||||||||
| /wxRequest/dataSet/ item/relation/ field |
A single field that was retrieved based on the request. Attributes:
|
||||||||||||||||||||||||
| /wxRequest/dataSet/ item/relation/ field/value |
The value of the current field, in the format defined in the request. |
Examples
Below is an example of a basic LookupData request document:
<dataSet reference="accounts">
<items>
<map>
<definition>
<?xml version="1.0" encoding="UTF-8"?>
<wxQuery
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="wxQuery.xsd"
id="root">
<data for="root">
<item/>
</data>
<startingTypes>
<startingType>a35234</startingType>
</startingTypes>
</wxQuery>
</definition>
</map>
</items>
<fields>
<field fieldId="a66969" reference="name">
<format type="text" />
</field>
</fields>
<relations>
<relation relationType="a36495" from="base"
reference="account_to_contact">
<fields>
<field fieldId="a36498" reference="position">
<format type="text" />
</field>
</fields>
</relation>
</relations>
</dataSet>
</wxRequest>
Below is the corresponding response document for the above example:
<callStatus status="success" />
<compatibilityLevel>1</compatibilityLevel>
<dataSet reference="accounts">
<item itemId="u7324">
<field fieldId="a66969" reference="name">
<value>WorkXpress</value>
</field>
<relation reference="account_to_contact" id="u7437"
relationType="a36495" baseItemTypeId="a35234" baseItemId="u7324"
targetItemTypeId="a35334" targetItemId="u7436">
<field fieldId="a36498" reference="position">
<value>Developer</value>
</field>
</relation>
</item>
</dataSet>
</wxResponse>
If you have any questions or would like assistance making some LookupData requests of your own, please feel free to comment below. My next post will be on how to use the AddItem request.


