Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

(0) ShareShare
ReportReport
Posted on by 1,204

Hi,

I'm trying to integrate AX2012 with PowerApps. So I tried to follow this article  where I need to create a web API and use it as custom connector in PowerApps.

In my attempt, I'd like to consume the SalesSalesOrderService in my API.

My httpGet method was able to return data, but I'm stuck with error while trying to create a sales order from post method in the API.

Here's my post method in SalesTableController:

[HttpPost]
public IHttpActionResult AddSalesOrder(SalesTable so)
{
    if (!ModelState.IsValid)
        return BadRequest("Invalid data.");

    var line = new AxdEntity_SalesLine()
    {
        ItemId = "D0001",
        SalesQty = 1,
        SalesUnit = "Pcs"
    };

    var order = new AxdEntity_SalesTable()
    {
        CustAccount = so.CustAccount,
        ReceiptDateRequested = so.ReceiptDateRequested,
        SalesLine = new AxdEntity_SalesLine[] { line }
    };

        var orderList = new AxdEntity_SalesTable[] { order };

        var callContext = new CallContext() { Company = "USMF" };

        ADSSalesOrderServiceClient client = new ADSSalesOrderServiceClient();

        AxdSalesOrder salesOrder = new AxdSalesOrder();

        salesOrder.SalesTable = orderList;

        return Ok(client.create(callContext, salesOrder));
}

Here's how I test my post method:

postman.png

Here's a clearer view of  the error message thrown:

api-exception.png

I tested the same logic in console application, can create the record in AX successfully. 

But why the service returns this error in API? I'm pretty sure I already provided values for mandatory fields except SalesId as it will be auto generated.

Plus, how can I debug deeper into the AX SalesSalesOrderService from my web API project? This is as far as I can think of and the error message it not detailed enough for me to dig further.

Thank You.

*This post is locked for comments

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

    If you create an order in AX, you don't need the external reference. If you create it from an external system, the reference to the external system is typically useful. That's the difference.

    If you don't like standard behavior of Dynamics AX, you can change it.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

    [quote]These are two different scenarios with different requirements.[/quote]

    But how is it different? It's still inserting the value into the same field in same table.

    What makes this field so important to make it mandatory? Isn't it just a reference field?

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

    It's not mandatory in AX, but it is mandatory for orders created from external systems via the AIF document service. These are two different scenarios with different requirements.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

    thank you martin for the direction.

    I checked the AIF exceptions, there's "there is no customer requisition number for the sales order" exception.

    It's SalesTable.PurchOrderFormNum field. But I don't understand.

    This is not a mandatory field. If I create a sales order normally in AX, ignoring this field would be no problem.

    But why suddenly it's required when creating SO from the service?

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Create Web API that Consumes SalesSalesOrderService for PowerApps Integration

    Despite the highlighted exception ("could not load file..."), it seems to me that the service has been called but something failed inside AX. Therefore I suggest you review AIF exception logs in AX and if it doesn't help, debug the document service to see what exactly happens.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans