Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Suggested answer

Code to prevent multiple locations on sales order when a specific location is involved

Posted on by 2
I have some locations that I would not like mixed with other locations on a sales order. I need a code that for example if I have a sales line coming from location 1 a user can only add additional items to that order from location 1 or 2 but no other locations. If the items do not come from location 1 or 2 they can combine whatever locations they want like normal. I hope that makes sense. 
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 62,157 Super User on at
    Code to prevent multiple locations on sales order when a specific location is involved
    As you know this can only be customized, sorry I haven't tested it in detail, hope the code below can give you some hints.
    pageextension 50223 MyExtension extends "Sales Order Subform"
    {
        layout
        {
            modify("Location Code")
            {
                trigger OnBeforeValidate()
                var
                    SalesLine: Record "Sales Line";
                begin
                    SalesLine.Reset();
                    SalesLine.SetRange("Document Type", Rec."Document Type");
                    SalesLine.SetRange("Document No.", Rec."Document No.");
                    SalesLine.SetRange("Location Code", 'location 1');
                    if SalesLine.FindSet() then
                        if (Rec."Location Code" <> 'location 1') or (Rec."Location Code" <> 'location 2') then
                            Error('user can only add additional items to that order from location 1 or 2 but no other locations');
                end;
            }
        }
    }
     
    Thanks.
    ZHU

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,671 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,756 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans