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

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Explicit value appears to be overwritten by standard/custom logic in OnInsert/OnAfterInsert

(0) ShareShare
ReportReport
Posted on by 41
From the page page 80008 "FA Transfer Out Process List", we create a Sales Header (Invoice) in action “Create FA Transfer Out”.

We explicitly assign "Responsibility Center" on the Sales Header using the source "From Centre Code". However, after Insert, the value does not persist—it appears to be overwritten by standard/custom logic in OnInsert/OnAfterInsert . I have tried by applying 
FAtransferRec.Validate("Location Code", SelRec."From Location");
 
page 80008 "FA Transfer Out Process List"
{
    //RM-23Dec2025
    ApplicationArea = All;
    Caption = 'FA Transfer Out Process Lists';
    PageType = List;
    CardPageId = "FA Transfer Out Process";
    SourceTable = "FA Transfer Out Process ";
    SourceTableView = sorting("No.");
    UsageCategory = Lists;
    RefreshOnActivate = true;
    InsertAllowed = false;
    // Editable = false;


 
    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field("No."; Rec."No.")
                {
                    ToolTip = 'Specifies the value of the No. field.', Comment = '%';
                    DrillDownPageId = "FA Transfer Out Process";
                }
                field("AI Code"; Rec."AI Code")
                {
 
                }
                field("FA Category"; Rec."FA Category")
                {
                    ApplicationArea = all;
                }
                field(Description; Rec.Description)
                {
 
                }
                field("From Centre Code"; Rec."From Centre Code")
                {
                    ToolTip = 'Specifies the value of the From Centre Code field.', Comment = '%';
                }
                field("To Centre Code"; Rec."To Centre Code")
                {
                    ToolTip = 'Specifies the value of the To Centre Code field.', Comment = '%';
                }
                field("From Location"; Rec."From Location")
                {
                    ToolTip = 'Specifies the value of the From Location field.', Comment = '%';
                }
                field(Amount; Rec.Amount)
                {
                    ToolTip = 'Specifies the value of the Amount field.', Comment = '%';
                }
                field(Quantity; Rec.Quantity)
                {
                    ToolTip = 'Specifies the value of the Quantity field.', Comment = '%';
                }
                field("Trans. Type"; Rec."Trans. Type")
                {
                    ToolTip = 'Specifies the value of the Trans. Type field.', Comment = '%';
                    Editable = false;
                }
                field("GST Group Code"; Rec."GST Group Code")
                {
                    ToolTip = 'Specifies the value of the GST Group Code field.', Comment = '%';
                }
                field("HSN/SAC Code"; Rec."HSN/SAC Code")
                {
                    ToolTip = 'Specifies the value of the HSN/SAC Code field.', Comment = '%';
                }
                field("GST Credit"; Rec."GST Credit")
                {
                    ToolTip = 'Specifies the value of the GST Credit field.', Comment = '%';
                }
 
                field("FA Posting Group"; Rec."FA Posting Group")
                {
                    ToolTip = 'Specifies the FA Posting Group.';
                }
 
                field("Project/ cost centre Code"; Rec."Project/ cost centre Code")
                {
                    ToolTip = 'Specifies the project or cost centre code.';
                }
 
                field("Unit Of Measure"; Rec."Unit Of Measure")
                {
                    ToolTip = 'Specifies the unit of measure.';
                }
                field("Create FA"; Rec."Create FA")
                {
                    Caption = 'Select for Transfer out Doc';
                    ApplicationArea = all;
                }
            }
        }
    }
    actions
    {
        area(Processing)
        {
            action("Create FA Transfer Out")
            {
                ApplicationArea = all;
                Image = Task;
                Promoted = true;
                PromotedCategory = Process;
                Enabled = FAEnable;
                Caption = 'Create Transfer Out Doc';
                // trigger OnAction()
                // var
                //     FAtransferRec: Record "Sales Header";
                //     ResCen: Record "Responsibility Center";
                //     NoSeries: Codeunit "No. Series";
                //     FALine: Record "Sales Line";
                //     FACreated: Boolean;
                //     FArchived: Record "FA Transfer Out Archived";
                // begin
 
                //     Clear(FACreated);
                //     // Rec.SetRange("Create FA", true);
                //     if Rec.FindSet() then begin
                //         repeat
                //             Rec.TestField("Create FA", true);
                //             FAtransferRec.SetRange("Responsibility Center", Rec."From Centre Code");
                //             FAtransferRec.SetRange("Sell-to Customer No", Rec."To Centre Code");
                //             if not FAtransferRec.FindFirst() then begin
                //                 FAtransferRec.Init();
                //                 FAtransferRec."Document Type" := FAtransferRec."Document Type"::Invoice;
                //                 if ResCen.Get(Rec."From Centre Code") then
                //                     FAtransferRec."No." := NoSeries.GetNextNo(ResCen."Transfer Sales Invoice", Today);
                //                 FAtransferRec.Validate("Location Code", Rec."From Location");
                //                 FAtransferRec.Amount := Rec.Amount;
                //                 FAtransferRec."Trans. Type" := FAtransferRec."Trans. Type"::"Transfer OUT";
                //                 FAtransferRec."Responsibility Center" := Rec."From Centre Code";
                //                 FAtransferRec."Sell-to Customer No." := Rec."To Centre Code";
                //                 FAtransferRec."Bill-to Customer No." := Rec."To Centre Code";
                //                 FAtransferRec."Sell-to Customer No" := Rec."To Centre Code";
                //                 FAtransferRec."Transfer Customer No." := Rec."To Centre Code";
                //                 if CustRec.get(FAtransferRec."Sell-to Customer No") then begin
                //                     FAtransferRec."Sell-to Customer Name" := CustRec.Name;
                //                     FAtransferRec."Bill-to Address" := CustRec.Address;
                //                     FAtransferRec."Sell-to Address" := CustRec.Address;
                //                     FAtransferRec."Bill-to Address 2" := CustRec."Address 2";
                //                     FAtransferRec."Bill-to City" := CustRec.City;
                //                     FAtransferRec."Sell-to Post Code" := CustRec."Post Code";
                //                     FAtransferRec."Bill-to Post Code" := CustRec."Post Code";
                //                     FAtransferRec."Bill-to Country/Region Code" := CustRec."Country/Region Code";
                //                     FAtransferRec."Sell-to Country/Region Code" := CustRec."Mobile No.";
                //                     FAtransferRec."Sell-to E-Mail" := CustRec."E-Mail";
                //                     FAtransferRec."Bill-to Contact" := CustRec.Contact;
                //                     FAtransferRec."Sell-to Contact" := CustRec.Contact;
 
                //                 end;
 
                //                 if FAtransferRec.Insert() then begin
                //                     FALine.init();
                //                     FALine."Document Type" := FAtransferRec."Document Type"::Invoice;
                //                     FALine."Document No." := FAtransferRec."No.";
                //                     FALine."Line No." := GetNextLineNo(FAtransferRec);
                //                     FALine.Type := FALine.Type::"Fixed Asset";
                //                     FALine."No." := Rec."No.";
                //                     FALine.Description := Rec.Description;
                //                     FALine."Location Code" := Rec."From Location";
                //                     FALine.Quantity := Rec.Quantity;
                //                     FALine."Unit Price" := Rec.Amount;
                //                     FALine.Insert();
                //                     FACreated := true;
                //                     // -------- ARCHIVE RECORD --------
                //                     FArchived.Init();
                //                     FArchived.TransferFields(Rec);
                //                     // FArchived."Archived Date" := Today;
                //                     // FArchived."Archived By" := UserId;
                //                     FArchived.Insert();
                //                     Rec.Delete();
                //                     // Rec.TransferFields(FArchived);
                //                 end;
                //             end else begin
                //                 // FALine.SetRange("Document Type", FAtransferRec."Document Type"::Invoice);
                //                 // FALine.SetRange("Document No.", FAtransferRec."No.");
                //                 // if FALine.FindFirst() then begin
                //                 FALine.init();
                //                 FALine."Document Type" := FAtransferRec."Document Type"::Invoice;
                //                 FALine."Document No." := FAtransferRec."No.";
                //                 FALine."Line No." := GetNextLineNo(FAtransferRec);
                //                 FALine.Type := FALine.Type::"Fixed Asset";
                //                 FALine."No." := Rec."No.";
                //                 FALine.Description := Rec.Description;
                //                 FALine."Location Code" := Rec."From Location";
                //                 FALine.Quantity := Rec.Quantity;
                //                 FALine."Unit Price" := Rec.Amount;
                //                 FALine.Insert();
 
                //                 // -------- DELETE SOURCE RECORD --------
                //                 // Rec.Delete();
 
                //                 // end;
                //             end;
                //         until Rec.Next() = 0;
                //         // Message('FA transfer Out %1 has been created!', FAtransferRec."No.");
                //         Message('FA transfer Out  has been created!');
                //     end;
 
                // end;
                trigger OnAction()
                var
                    SelRec: Record "FA Transfer Out Process "; // or your SOURCE table
                    FAtransferRec: Record "Sales Header";
                    ResCen: Record "Responsibility Center";
                    NoSeries: Codeunit "No. Series";
                    FALine: Record "Sales Line";
                    FACreated: Boolean;
                    FArchived: Record "FA Transfer Out Archived";
                    SalesSetup: Record "Sales & Receivables Setup";
 
                begin
                    Clear(FACreated);
                    SalesSetup.Get();
 
                    CurrPage.SetSelectionFilter(SelRec);
 
                    if SelRec.IsEmpty() then
                        Error('Please select at least one record.');
 
                    if SelRec.FindSet() then begin
                        repeat
                            SelRec.TestField("Create FA", true);
                            SelRec.TestField("To Centre Code");
                            SelRec.TestField("Trans. Type", 'Transfer OUT');
 
                            if SelRec.Amount = 0 then
                                Error('Amount must not be zero for FA No. %1.', SelRec."No.");
                            FAtransferRec.Reset();
                            FAtransferRec.SetRange("Responsibility Center", SelRec."From Centre Code");
                            FAtransferRec.SetRange("Sell-to Customer No.", SelRec."To Centre Code");
 
                            if not FAtransferRec.FindFirst() then begin
                                FAtransferRec.Init();
                                FAtransferRec."Document Type" := FAtransferRec."Document Type"::Invoice;
 
                                if ResCen.Get(SelRec."From Centre Code") then
                                    FAtransferRec."No." := NoSeries.GetNextNo(ResCen."Transfer Sales Invoice", Today)
 
                                else
                                    FAtransferRec."No." := NoSeries.GetNextNo(SalesSetup."Invoice Nos.", Today);



 
                                FAtransferRec.Amount := SelRec.Amount;
                                FAtransferRec."Trans. Type" := FAtransferRec."Trans. Type"::"Transfer OUT";
                                FAtransferRec."Responsibility Center" := SelRec."From Centre Code";
                                FAtransferRec."Location Code" := SelRec."From Location";
                                FAtransferRec."Shortcut Dimension 2 Code" := SelRec."To Centre Code"; //Centre Code
                                FAtransferRec."Shortcut Dimension 1 Code" := SelRec."Project/ cost centre Code"; //Project Code
                                FAtransferRec."Posting No. Series" := NoSeries.GetNextNo(ResCen."Posted Trf Sales Invoice");
                                FAtransferRec."Sell-to Customer No." := SelRec."To Centre Code";
                                FAtransferRec."Bill-to Customer No." := SelRec."To Centre Code";
                                FAtransferRec."Sell-to Customer No" := SelRec."To Centre Code";
                                FAtransferRec."Transfer Customer No." := SelRec."To Centre Code";
 
                                if CustRec.Get(FAtransferRec."Sell-to Customer No.") then begin
                                    FAtransferRec."Sell-to Customer Name" := CustRec.Name;
                                    FAtransferRec."Bill-to Address" := CustRec.Address;
                                    FAtransferRec."Sell-to Address" := CustRec.Address;
                                    FAtransferRec."Sell-to E-Mail" := CustRec."E-Mail";
                                    FAtransferRec."Sell-to Address 2" := CustRec."Address 2";
                                    FAtransferRec."Sell-to City" := CustRec.City;
                                    FAtransferRec."Sell-to Post Code" := CustRec."Post Code";
                                    FAtransferRec."Sell-to Country/Region Code" := CustRec."Country/Region Code";
 
                                end;
 
                                FAtransferRec.Insert(); // Run OnInsert triggers
 
                                // FAtransferRec.Validate("Location Code", SelRec."From Location");
                                // FAtransferRec.Validate("Shortcut Dimension 2 Code", SelRec."To Centre Code");
                                // FAtransferRec.Validate("Shortcut Dimension 1 Code", SelRec."Project/ cost centre Code");
                                // FAtransferRec.Validate("Posting No. Series", ResCen."Posted Trf Sales Invoice");
 
                                FAtransferRec.Modify(true);
 
                            end;
 
                            // ---------- CREATE LINE ----------
                            FALine.Init();
                            FALine."Document Type" := FAtransferRec."Document Type"::Invoice;
                            FALine."Document No." := FAtransferRec."No.";
                            FALine."Line No." := GetNextLineNo(FAtransferRec);
                            FALine.Type := FALine.Type::"Fixed Asset";
                            FALine."No." := SelRec."No.";
                            FALine.Description := SelRec.Description;
                            FALine."Location Code" := SelRec."From Location";
                            FALine.Quantity := SelRec.Quantity;
                            FALine."Unit Price" := SelRec.Amount;
                            FALine.Insert();
 
                            // ---------- ARCHIVE ----------
                            FArchived.Init();
                            FArchived.TransferFields(SelRec);
                            FArchived.Insert();
 
                            SelRec.Delete();
 
                        until SelRec.Next() = 0;
 
                        Message('FA transfer Out has been created for selected records.');
                    end;
                end;
 
            }
            action(MarkCreateFA)
            {
                Caption = 'Mark Create FA';
                Image = Check;
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                ToolTip = 'Marks Create FA as true for the selected records.';
                Enabled = FAEnable;
 
                trigger OnAction()
                var
                    SelRec: Record "FA Transfer Out Process ";
                    CountUpdated: Integer;
                begin
 
                    CountUpdated := 0;
                    // Only selected rows
                    CurrPage.SetSelectionFilter(SelRec);
                    if SelRec.IsEmpty() then
                        Error('Please select at least one record.');
 
                    if SelRec.FindSet() then begin
                        repeat
                            if not SelRec."Create FA" then begin
                                SelRec."Create FA" := true;
                                SelRec.Modify(true);
                                CountUpdated += 1;
                            end;
                        until SelRec.Next() = 0;
                    end;
                    Message('%1 record(s) marked as Create FA.', CountUpdated);
                end;
            }
 
        }
    }
    local procedure GetNextLineNo(SalesHeader: Record "Sales Header"): Integer
    var
        SalesLine: Record "Sales Line";
    begin
        SalesLine.Reset();
        SalesLine.SetRange("Document Type", SalesHeader."Document Type");
        SalesLine.SetRange("Document No.", SalesHeader."No.");
 
        if SalesLine.FindLast() then
            exit(SalesLine."Line No." + 10000)
        else
            exit(10000);
    end;
 
    trigger OnOpenPage()
    var
        UserSetup: Record "User Setup";
 
    begin
        if UserSetup.Get(UserId) then
            if UserSetup."Allow Create FA" then
                FAEnable := true
            else
                FAEnable := false;
 
    end;
 
    var
        CustRec: Record Customer;
        FAEnable: Boolean;
 
}
Categories:
I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 81 Super User 2026 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 56 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans