Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Display Warehouse stats

Posted on by 200

Here I have a condition where I needed to display status

As 'Complete' if the order is fully shipped, and if the sales order is partially shipped then the status must be 'Picked' and if the order is just raised or Open then the status must be 'Open'.

I written the Al code for sales order which is open, 

But I want for fully shipped and partially shipped,

This code is for order which is open that I written:

codeunit 50133 "Warehouse stats"
{
    var
        cdu_CommonHelper: Codeunit "Common Helper";

    procedure Warehousestats()
    var
        rec_SalesHeader: Record "Sales Header";
        rec_SalesLine: Record "Sales Line";
        en_DocumentType: Enum "Sales Document Type";
        en_status: Enum "Sales Document Status";
        Status: Text;
    begin
        rec_SalesHeader.SetRange("Document Type", en_DocumentType::Order);
        rec_SalesHeader.SetFilter("Order Date", '=%1', Today);
        if rec_SalesHeader.FindSet() then
            repeat
                rec_SalesLine.SetRange("Document No.", rec_SalesHeader."No.");
                if rec_SalesLine.FindSet() then
                    repeat
                        if rec_SalesHeader.Status = en_status::Open then begin

                            Message('%1 OPEN', rec_SalesLine."Document No.");
                        end

                    until rec_SalesLine.Next() = 0;
            until rec_SalesHeader.Next() = 0;
    end;
Here it's for order which is open, and also wanted to display status as 'Open'
So how can be done in Al code please help
Thankyou.
Categories:
  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Display Warehouse stats

    Yes it's good now, but how can I get all orders whether it is fully or partially shipped or open?

    In this code I am getting message for order for complete shipped but I also have partially shipped and open sales order not getting message for that, so how can I get message for all conditions simultaneously?

    This is my final code

      procedure Warehousestats()
        var
            rec_SalesHeader: Record "Sales Header";
            rec_SalesLine: Record "Sales Line";
            en_DocumentType: Enum "Sales Document Type";
            en_status: Enum "Sales Document Status";
            Status: Text;
        begin
            rec_SalesHeader.SetRange("Document Type", en_DocumentType::Order);
            rec_SalesHeader.SetFilter("Order Date", '=%1', Today);
            if rec_SalesHeader.FindSet() then
                repeat

                    rec_SalesLine.SetRange("Document Type", rec_SalesHeader."Document Type");
                    rec_SalesLine.SetRange("Document No.", rec_SalesHeader."No.");
                    rec_SalesLine.SetRange(Type, rec_SalesLine.Type::Item);

                    rec_SalesLine.SetRange("Completely Shipped", false);
                    if rec_SalesLine.IsEmpty then begin
                        Message('%1 Complete', rec_SalesHeader."No.");

                    end;

                    rec_SalesLine.SetFilter("Quantity Shipped", '<>%1', 0);
                    if not rec_SalesLine.IsEmpty then begin
                        Message('%1 Picked', rec_SalesHeader."No.");

                    end;

                    if rec_SalesHeader.Status = en_status::Open
                     then begin
                        Message('%1 OPEN', rec_SalesHeader."No.");

                    end;

                until rec_SalesHeader.Next() = 0;
        end;

    }
  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Display Warehouse stats

    What is the Order Date of the 2nd Sales Order?

    Did you create Item Type lines?

    Does Quantity Shipped field has a value except 0?

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Display Warehouse stats

    Yes , I think so there is some problem in if loop,

    I created new order and fully shipped that it showed status complete and when I create new order and only partially shipped not getting 'Picked' status message,but I was getting this mess on previous order which was partially shipped.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Display Warehouse stats

    Is your Order fully invoiced or not?

    It will show complete if all the lines are fully shipped.

    Are all your lines fully shipped?

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Display Warehouse stats

    Yes I get that, but not the complete shippede part?

    Rec,salesline.setrange("Completely shipped", false)

    Here when the all quantity get shipped I should get Complete status right? But not getting it.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Display Warehouse stats

    The completely shipped and invoiced orders will be deleted and moved to posted sales shipments/invoices.

    if the order is only shipped and not invoiced then they will still be in Sales Orders.

    I am not following exactly what is the issue but you may have to change the code based on your requirement.

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Display Warehouse stats

    Hey, Thanks for this one,

    But completely shipped sales order will be on posted sales invoice right?, in that case the above code for completely shipped orders is not working for me, the message is still showing when I didn't shipped any orders or posted,

    So please can you help in that?

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Display Warehouse stats

    Please try something like this.

    procedure Warehousestats()
        var
            rec_SalesHeader: Record "Sales Header";
            rec_SalesLine: Record "Sales Line";
            en_DocumentType: Enum "Sales Document Type";
            en_status: Enum "Sales Document Status";
            Status: Text;
        begin
            rec_SalesHeader.SetRange("Document Type", en_DocumentType::Order);
            rec_SalesHeader.SetFilter("Order Date", '=%1', Today);
            if rec_SalesHeader.FindSet() then
                repeat
                    rec_SalesLine.SetRange("Document Type", rec_SalesHeader."Document Type");
                    rec_SalesLine.SetRange("Document No.", rec_SalesHeader."No.");
                    rec_SalesLine.SetRange(Type, rec_SalesLine.Type::Item); //change as per your requirement
                    rec_SalesLine.SetRange("Completely Shipped", false);
                    if rec_SalesLine.IsEmpty then begin
                        Message('%1 Complete', rec_SalesHeader."No.");
                        exit;
                    end;

                    rec_SalesLine.SetFilter("Quantity Shipped", '<>%1', 0);
                    if not rec_SalesLine.IsEmpty then begin
                        Message('%1 Picked', rec_SalesHeader."No.");
                        exit;
                    end;

                    if rec_SalesHeader.Status = en_status::Open then
                        Message('%1 OPEN', rec_SalesHeader."No.");

                until rec_SalesHeader.Next() = 0;
        end;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans