Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to read json body ...
Finance forum
Suggested answer

How to read json body in a D365 odata entity ?

Posted on by 7
Hello,
 
I have to update a table via odata custom entity.
 
We try to call this entity with postman passing the new value in the json body like this :
 
 
This return 204 but nothing happens and when i try to debug the postload method, i can see that in the this that the value of /employeeResponsibleNumber/ is empty while /AccountNum/ is not.
 
How can i find the expected value ?
 
Thank you for your answers.
Categories:
  • Julien LECOEUR Profile Picture
    Julien LECOEUR 7 on at
    How to read json body in a D365 odata entity ?
     
    Thank you for your answer wich will help me better understand D365.
     
    Thanks
  • Julien LECOEUR Profile Picture
    Julien LECOEUR 7 on at
    How to read json body in a D365 odata entity ?
    Hi Martin,
     
    You are right, i had a bad reasonning.
     
    I let myself be influenced by the request made to me rather than focusing on the code.
     
    I simply change the field in the entity and the postman call.
     
    Thank you for your answer, and thanks to Layan Jwei.
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    Navneeth Nagrajan 1,339 on at
    How to read json body in a D365 odata entity ?
    Hi,
     
    In postLoad() method you can write something like this.
    public void postLoad()
    {
        // Overridden to have ability to create event handlers.
        super();
     
        this.EmployeeResponsibleNumber = <TableName>::find()
     
       or 
        this.EmployeeResponsibleNumber = this.<methodname>(this.employeeResponsibleNumber);
       
    }
     
     
    You can use the initializeEntityDataSOurce and write something like this which should work for update operations. 
     
     public void initializeEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
       super(_entityCtx, _dataSourceCtx);
     
       switch (_dataSourceCtx.name())
    {
        case dataEntityDataSourceStr(<EntityName>, <datasourcename>):
                <TableBufferName> variableName = <TableName>::find(this. employeeResponsibleNumber);
     
                 If(variableName)
                 {
                       <tablename>.selectForUpdate(true);
    _dataSourceCtx.setBuffer(<buffername>);
    _dataSourceCtx.getBuffer().validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
    _dataSourceCtx.setDatabaseOperation(DataEntityDatabaseOperation::Update);
                 }
                 break;
    }
     
    }
     
    You have to pass the AccountNum buffer too in this case to make your code work.
     
    Share your code snippet. Based on this, we can respond to the set of questions.
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    How to read json body in a D365 odata entity ?
    Your code in postLoad() method is completely wrong. Updating CustTable every time when a record is being exported is both logically wrong and a huge problem for performance.
     
    What you should do there is assigning a value of your virtual field (e.g. this.MyVirtualField = str2int(this.EmployeeResponsibleNumber)). But if you're doing it for performance, you'll be better off using a computed column instead of a virtual field.
  • Julien LECOEUR Profile Picture
    Julien LECOEUR 7 on at
    How to read json body in a D365 odata entity ?
    Hi Layan Jwei,
     
    Thank you for your answer.
     
    Yes it's a custom entity, to explain to you, we have performance issues with custCustomerV3Entity because we have too much datas to export.
     
    So, i create some custom entities with less information to reduce export times depending on the various themes.
     
    Here, we want to import / export some specific information about customers in particular the employeeResponsibleNumber but if the name is the same, we don't use it like in custCustomerV3. Here, we just insert in a custom field in custtable table called "MainContactWorker".
     
    I use the postLoad method because it seems to me that it is activated on each line and i use it in this way :
     
     
    But as i said, nothing appends because this.EmployeeResponsibleNumber is empty.
     
    Thank you.
  • Layan Jwei Profile Picture
    Layan Jwei 4,742 Super User on at
    How to read json body in a D365 odata entity ?
    Hi Julien,

    You mentioned postLoad method, so do you mean you are filling the employee responsible number in postload method? I mean is the field virtual field?
    if yes can you share the code please?

    And what datasources do u have in ur entity?
     

    Thanks,
    Layan Jweihan

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans