Bojensen Blogs

Calling the Update Operation on Services in AX 2012

Calling the update operation on web services can range from simple
to very complicated depending on the entities/tables you are updating.  If the entity you are calling is not a date
effective entity, then the service’s update method is easy to call.

You can tell if a table is date effective by going in the
AOT to the Data Dictionary > Tables > Find the tables that comprise the
service > Right-click on the table and choose Properties.  In the property sheet, look for the
ValidTimeStateFieldType property.  If the
property is set to “None” then the table is NOT date effective.  You will need to look at every table in the
service to see if that property is set to none.

If the service is not date effective, like the sales order
service, then you can call the service using the find and then the update operations.  In the example below, I retrieve a sales
order using the find method and then I update the SalesQty and SalesPrice
fields on each sales line in the retrieved sales order.






Unlike the sales order service, the customer service is date
effective because it contains the DirPersonName, DirOrganizationName,
DirPartyLocation, etc. tables which have their ValidTimeStateFieldType
properties set to something other than None.
Date effective services have properties added at the document level (the
highest level in the service) to indicate how you want to set the date effective
entities.  The properties are ValidTimeStateType,
ValidAsOfDateTime, ValidFromDateTime and ValidToDateTime.  Either you can set those at the document
level or you can set the date effective fields on each entity in the service
that is date effective.  In the example
code below, I call the read method to retrieve a customer and then I create a
new instance of a customer, set the date effective properties on the document according
to what they are on the retrieved customer and then update the CreditMax field
on the customer.



As an alternative to setting the properties at the document
level (AxdCustomer) I can set the date effective properties on each table in
the service that is date effective.  As
you’ll notice the code get clunkier and more difficult to do programmatically.  The example code below accomplishes the same
goal of retrieving the customer using the read method and then it updates the
CreditMax for that customer.




Calling the Update Operation on Services in AX 2012 – Microsoft Dynamics AX Support – Site Home – MSDN Blogs

Comments are closed.