microsoft / Dynamics-AX-Integration

Dynamics AX Integration samples and demos.
287 stars 356 forks source link

How to parse the response from insert? #62

Closed RobvanB closed 6 years ago

RobvanB commented 6 years ago

I'm using the MS sample code to create a journal using OData. I can create the header fine. However, when the header is created, the journal number is returned in the response. How do I get the journal number from the response?

The record is created using resp = context.SaveChanges();

resp is of type DataServiceResponse, and contains the data in Json format (if I understand this correctly) - but I'm having trouble pulling gout the one field with the new journal ID. How do I get the new journal ID from the response?

tek9iner commented 6 years ago
        DataServiceResponse response = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties);

        foreach (ChangeOperationResponse change in response)
        {
            EntityDescriptor descriptor = change.Descriptor as EntityDescriptor;

            if (descriptor != null)
            {

                var ret_entity = descriptor.Entity as NameOfYourEntity;

                ..do whatever you need to do with ret_entity should have all of the props available and populated for you from your newly inserted record

            }
        }
RobvanB commented 6 years ago

Perfect, thanks!