In a partial update, in addition to required fields that must always be present, only the data that is to be updated is contained in the inbound message. All the other field values that are not contained in the inbound update request message remain unchanged in the database table unless there is some defaulting logic. For example, there may be a FullName field that is defaulted from the FirstName and LastName fields. If the FirstName field is in the submitted data and has changed and the FullName field is not in the submitted data, then the FullName field in the table will be updated by the defaulting logic to reflect the change to the FirstName field.
The inbound message for a partial update must contain the entity key of the record to be updated in addition to the data to be updated. In the following XML, the record entity key is contained in the EntityKeyList tags.
The signature for the update service operation is: void update(EntityKey[], <DocumentObject>), where the <DocumentObject> contains one or more tables (for example, SalesTables or CustTables). The number of tables in the <DocumentObject> parameter and the length of the EntityKey array must match and the EntityKey[n] must reference the corresponding table in the <documentType> parameter.
A partial update has the update action in the header and for each record in the message contains one of the action attributes (see previous table).
For example, if you pass in a message to update the customer, you can use attributes to specify that the following updates should occur as shown in the following XML message:
-
The customer record should be updated
-
A customer address should be updated
-
A new customer address should be created
-
A customer address should be deleted
<?xml version="1.0" encoding="utf-8" ?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2008/
01/documents/Message">
<Header>
<Action>http://www.microsoft.com/dynamics/services/2008/
01/CustomerService/update</Action>
</Header>
<Body>
<MessageParts xmlns = "http://schemas.microsoft.com/dynamics/2008/01/documents/Message">
<EntityKeyList xmlns="http://schemas.microsoft.com/dynamics/
2006/02/documents/EntityKeyList">
<EntityKey xmlns="http://schemas.microsoft.com/dynamics/
2006/02/documents/EntityKey">
<KeyData>
<KeyField>
<Field>AccountNum</Field>
<Value>4507</Value>
</KeyField>
</KeyData>
</EntityKey>
</EntityKeyList>
<Customer xmlns="http://schemas.microsoft.com/dynamics/
2008/01/documents/Customer">
<DocPurpose>Original</DocPurpose>
<SenderId>DAT</SenderId>
<CustTable class="entity" action="update">
<AccountNum>4507</AccountNum>
<CreditMax xsi:nill="true"/>
<CustGroup>40</CustGroup>
<PartyType>Organization</PartyType>
<RecId>5637144604</RecId>
<RecVersion>779953820</RecVersion>
<CustAddress class="entity" action="update">
<AddrRecId>5637144604</AddrRecId>
<AddrTableId>77</AddrTableId>
<DlvMode>AIR</DlvMode>
<RecId>5637145089</RecId>
<RecVersion>1</RecVersion>
</CustAddress>
<CustAddress class="entity" action="create">
<Address>2100 5th Street Baltimore, MD
21210 US</Address>
<AddrTableId>77</AddrTableId>
<City>Baltimore</City>
<CountryRegionId>US</CountryRegionId>
<County>Baltimore</County>
<DlvMode>U11A</DlvMode>
<DlvTerm>TERMNA3RD</DlvTerm>
<Name>Molly Clark</Name>
<ShipCarrierAccount>234-45678
</ShipCarrierAccount>
<ShipCarrierAccountCode>UPS
</ShipCarrierAccountCode>
<ShipCarrierBlindShipment>No
</ShipCarrierBlindShipment>
<ShipCarrierID>U11A</ShipCarrierID>
<ShipCarrierResidential>No
</ShipCarrierResidential>
<State>MD</State>
<Street>2100 5th Street</Street>
<TimeZone>GMTMINUS0800PACIFICTIME
</TimeZone>
<type>AltDlv</type>
<ZipCode>21210</ZipCode>
</CustAddress>
<CustAddress class="entity" action="delete">
<RecId>5637145099</RecId>
<RecVersion>1</RecVersion>
</CustAddress>
</CustTable>
</Customer>
</MessageParts>
</Body>
</Envelope>
The following action attributes specify the associated updates:
-
<CustTable class="entity" action="update"> - specifies that the customer should be updated.
-
<CustAddress class="entity" action="update"> - specifies that the address should be updated.
-
<CustAddress class="entity" action="create"> - specifies that the address should be created.
-
<CustAddress class="entity" action="delete"> - specifies that the address should be deleted.
Valid Update Attribute Combinations
If a message contains the update action in the header, the following three scenarios are the only valid combinations of update attributes:
-
No attributes - Specifies a full update. This is the same as using the replace attribute at the top level.
-
The replace attribute at the top-level table - Specifies that all records will be replaced. If any child records specify any other attributes, an error will be generated.
-
The update attribute at the top-level table - Specifies that the record will be updated. All the child records must have either a create, update, or delete attribute.
Setting Fields to NULL
If you do not have SP1 installed, you have used the update action attribute, and you want to specify that a field should be NULL, you must include the field element in the message and use the nil attribute as shown in this code example:
<CreditMax xsi:nil="true"/>
If you have SP1 installed and you want to specify that a field should be NULL, the field must be in the message and you must send in the X++ NULL value for the field based on its data type. For more information about X++, XML, and .NET data type conversions, see AIF Services and Primitive Data Type Conversions for XML and .NET Framework.