Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse the response from insert? #62

Closed
RobvanB opened this issue Apr 2, 2018 · 2 comments
Closed

How to parse the response from insert? #62

RobvanB opened this issue Apr 2, 2018 · 2 comments

Comments

@RobvanB
Copy link

RobvanB commented Apr 2, 2018

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
Copy link

tek9iner commented Apr 4, 2018

        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
Copy link
Author

RobvanB commented Apr 5, 2018

Perfect, thanks!

@RobvanB RobvanB closed this as completed Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants