web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Display Warehouse stats

(0) ShareShare
ReportReport
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.
I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    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;
  • Dividutt Profile Picture
    200 on at

    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?

  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    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
    200 on at

    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
    60,993 Super User 2025 Season 2 on at

    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
    200 on at

    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
    60,993 Super User 2025 Season 2 on at

    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
    200 on at

    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;

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans