Skip to main content

Notifications

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

Business Central

Posted on by 200

I want to show alert message if any items  having location code more than one in item bin content how can be done in Al code? 

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    Yes I wanted this one, thanks now its working.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Business Central

    Then you can use something like this:

    codeunit 50100 ItemTools
    {
        trigger OnRun()
        var
            loaction: Record Location;
            Item: Record Item;
            NoOfLocations: Integer;
            LocationString: Text;
            BinContect: Record "Bin Content";
        begin
            NoOfLocations := 0;
            LocationString := '';
            Item.SetRange(Blocked, false);
            If Item.FindSet(false, false) then
                repeat
                    BinContect.Reset();
                    BinContect.SetRange("Item No.", Item."No.");
                    if BinContect.Count > 1 then Message('Item No. %1 has %2 related Bin Content records',Item."No.",BinContect.Count);
                    
                until Item.Next() = 0;
        end;
    
    }
    

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    Yes, but I want the code that triggers the message which check each Items that has more than one location code in its item bin content, is it possible we can do that? please do help only for that.

    pastedimage1677433545415v2.png

  • Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Business Central

    I am still a bit confused around how you actually plan to use this function.

    But this code only triggers the message for Items located in more than one location and where Bin's are also used on the location.

    codeunit 50100 ItemTools
    {
        trigger OnRun()
        var
            loaction: Record Location;
            Item: Record Item;
            NoOfLocations: Integer;
            LocationString: Text;
        begin
            NoOfLocations := 0;
            LocationString := '';
            Item.SetRange(Blocked, false);
            If Item.FindSet(false, false) then
                repeat
    
                    if loaction.FindSet(false, false) then
                        repeat
    
                            Item.Setfilter(Item."Location Filter", loaction.Code);
                            Item.SetFilter("Bin Filter", '<>%1', '');
                            If Item.Inventory > 0 then begin
                                NoOfLocations  = 1;
                                if NoOfLocations = 1 then LocationString := loaction.Code;
                                If NoOfLocations > 1 then LocationString := LocationString   ' '   loaction.Code;
                            end;
                        until loaction.Next() = 0;
                    if NoOfLocations > 1 then Message('Item %1 is avalible on these %2 locations %3', Item."No.", NoOfLocations, LocationString);
                until Item.Next() = 0;
        end;
    
    }
    

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    bin-1.png

    In this code I am getting all location code  of items which is in bin content but i want only that items which has more than one location code.

    procedure loc()

       var

           Item: Record Item;

           Bin: Record "Bin Content";

           loaction: Record Location;

           NoOfLocations: Integer;

           LocationString: Text;

       begin

           NoOfLocations := 0;

           LocationString := '';

           Item.SetRange(Blocked, false);

           if Item.FindSet() then

               repeat

                   if Bin.FindSet() then

                       repeat

                           Item.SetRange("No.", bin."Item No.");

                           if (bin."Location Code" > Format(1)) then begin

                               Message('%1', Bin."Location Code");

                           end;

                       until Bin.Next() = 0;

               until item.Next() = 0;

       end;

    I needed only those items which has more than one location code(item bin content).

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Business Central

    But how are you going to present those data?

    In a report ?

    And is it the bin that is important or the location or both?

    Running through possible hunders or thousands of items and display a message for every items does not seem like a good appoach.

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    The alert needs to look at the Item Card and then report if there are Items which have more than one Bin Location (Item Bin Content).

    so needed solution for this.

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    Ok thankyou will try and update.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Business Central

    You can try this code where you can send in the item you want to check.

    codeunit 50100 ItemTools
    {
        procedure CountLocations(Item: Record Item)
        var
            loaction: Record Location;
            NoOfLocations: Integer;
            LocationString: Text;
        begin
            NoOfLocations := 0;
            LocationString := '';
            if loaction.FindSet(false, false) then
                repeat
    
                    Item.Setfilter(Item."Location Filter", loaction.Code);
                    Item.CalcFields(Inventory);
                    If Item.Inventory > 0 then begin
                        NoOfLocations  = 1;
                        if NoOfLocations = 1 then LocationString := loaction.Code;
                        If NoOfLocations > 1 then LocationString := LocationString   ' '   loaction.Code;
                    end;
                until loaction.Next() = 0;
                if NoOfLocations >1 then Message('Item %1 is avalible on these %2 locations %3',Item."No.",NoOfLocations,LocationString);
    
        end;

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: Business Central

    YES, so if any item have more than one bin location code then i needed to trigger alert or display message that item has more than one location code.

    so needed al code to display that.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans