Using the WorkXpress API: UpdateItem
Earlier 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 update existing Items in a WorkXpress application using the UpdateItem API function. UpdateItem allows you to set Fields, create Relationships and recycle and delete Items & Relationships. Like the other functions, you can make many UpdateItem requests in one 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 UpdateItem 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 updated. 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 any fields that should be updated on the items that were found in the items node. | ||||||||||||||||||
| /wxRequest/dataSet/ fields/field |
A single field to update on the Item. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ fields/field/ value |
Value to set into the field. | ||||||||||||||||||
| /wxRequest/dataSet/ relations |
Root node for relations that should be added or updated with the current item. | ||||||||||||||||||
| /wxRequest/dataSet/ relations/relation |
Defines a single relation to be added or updated. If the action is not "add", the attributes will be used to look up an existing relation. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields |
Root node for the fields that should be set on the relationship. | ||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field |
A single field to be set on the relationship. Attributes:
|
||||||||||||||||||
| /wxRequest/dataSet/ relations/relation/ fields/field/ value |
Value to set into the field. |
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 |
Defines an item that was updated. One item node is returned for each item that was updated by WorkXpress. Attributes:
|
|||||||||
| /wxRequest/dataSet/ item/relation |
Defines a relationship that was added or updated. Returns one relation node for each relationship from the item that was added or updated by WorkXpress. Attributes:
|
Examples
Below is an example of a basic UpdateItem request document:
<dataSet action="update" reference="account_update">
<items>
<item itemId="u7563" />
</items>
<fields>
<field fieldId="a66969">
<value>WorkXpress</value>
</field>
</fields>
<relations>
<relation action="update" oppositeItemId="u7436"
reference="account_to_contact" relationType="a36495"
startingSide="base">
<fields>
<field fieldId="a36498">
<value>Intern</value>
</field>
<field fieldId="a36513">
<value>foo [at] example [dot] com</value>
</field>
</fields>
</relation>
</relations>
</dataSet>
<dataSet action="recycle" reference="account_recycle">
<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>a5543</startingType>
</startingTypes>
<paramGroup id="wx4adfb3c227d12">
<join>and</join>
<fieldSearch id="wx4adfb3d738a91">
<fieldId>a39651</fieldId>
<operator>fieldLessThanEqualTo</operator>
<input>
&lt;?xml version="1.0"?&gt;
&lt;search_value&gt;
&lt;first_value&gt;
-1 years
&lt;/first_value&gt;
&lt;/search_value&gt;
</input>
</fieldSearch>
</paramGroup>
</wxQuery>
</definition>
</map>
</items>
</dataSet>
</wxRequest>
Below is the corresponding response document for the above example:
<callStatus status="success" />
<compatibilityLevel>1</compatibilityLevel>
<dataSet reference="account_update">
<item itemId="u7563">
<relation reference="account_to_contact" relationId="u7564" />
</item>
</dataSet>
<dataSet reference="account_recycle">
<item itemId="u1782"></item>
</dataSet>
</wxRequest>
If you have any questions or would like assistance making some UpdateItem requests of your own, please feel free to comment below. My next post will be on how to use the ExecuteAction request.


