Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

OnPostingLoad not working in API call x++

(0) ShareShare
ReportReport
Posted on by 191

Hi Community Experts,

I have one situation with the PurchaseOrderLinesV2 Data entity,

I have added some custom fields with "Is Computable Field" property set to "No.

And some methods in the entity through extension and I am calling those methods inside the "onPostingLoad" event handler of that data entity.

pastedimage1674453818786v1.png

This event handler is getting triggered fine and returning data in fields correctly when I am calling it through browser with this URL.

https://xxxxxxxxxxxxxxxxxxxxxxxxx.axcloud.dynamics.com/data/PurchaseOrderLinesV2

But when I call the same data entity from postman its not showing any data in the fields.

pastedimage1674454127251v2.png

"OnPostingLoad" is getting called when I am calling the entity from postman, but it is not returning data as it returns in browser.

Where should I put my code to get data in my custom fields?

Usual helpful responses are expected :)

Best Regards.

  • alinawaz Profile Picture
    alinawaz 191 on at
    RE: OnPostingLoad not working in API call x++

    Hi Martin,

    Thanks for pointing me to the correct direction.

    I just put the "Crosscompany" keyword in my select statement and its now working fine in postman as well.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    RE: OnPostingLoad not working in API call x++

    Yes, VendRFQTrans isn't shared across companies, therefore your query returns VendRFQTrans record from the current company (if such a record exists). Even if you call the code with identical parameters, you'll may different result if it's executed in different company context.

  • Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    RE: OnPostingLoad not working in API call x++

    If you aren't aware of any difference in the data (using a different company or different trans ID), use the debugger to see the difference there.

    I suspect that VendRFQTrans isn't shared across companies (I can't check it at the moment) and therefore your code works correctly only if it's executed in the same company that you have in _dataAreaId.

  • alinawaz Profile Picture
    alinawaz 191 on at
    RE: OnPostingLoad not working in API call x++

    Hi Martin,

    Thanks for your suggestion about the extension class and event handler. I will do so.

    Upon further debugging I have found-out this buffer only has data when I call the entity from browser.

    pastedimage1674459012051v1.png

    When I call the same entity from Postman this buffer is empty.

    The request URL is same in postman and browser, the data I am passing in the method is same. This buffer is behaving differently in case of postman.

  • Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    RE: OnPostingLoad not working in API call x++

    Your first test is using OData too, therefore if it works there, it proves that it does work. You're probably using different parameters from Postman. Please test the same thing - copy the request URL that Postman is using and open it in a browser.

    By the way, it seems that you've added an event handler to an extension class, which isn't the right approach and you should be getting a compuiler warning. The easist approach is using a CoC extension of postLoad().

    If you insist on an event handler, put it to a separate class.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans