Intercompany Module

souoiksouoik Member Posts: 128
edited 2024-03-25 in NAV Three Tier
Hello please i create a function where using from bottom to send to Company partner in the same instance , from Posted Sales Shipment
This my code for the sales line is not generate correctlly i dont why not inserted Unite of measure
codeunit 90110 TTMgt
{
TableNo = "Sales Header";
Subtype = Normal;
Permissions = tabledata "Sales Header" = rimd;
trigger OnRun()
begin
SetParameter(Rec);
Rec.SETRECFILTER();
Rec.Reset();

end;

local procedure SetParameter(Rec: Record "Sales Header")
begin
SetParam := Rec;
end;


procedure CreatSalesOrder(SalesShipmentHeader: Record "Sales Shipment Header")
var
PSalesShipHeader: Record "Sales Shipment Header";
PshipmentLine: Record "Sales Shipment Line";
SalesHeader: Record "Sales Header";
SalesHeader2: Record "Sales Header";
SalesLine: Record "Sales Line";
ICPartner: Record "IC Partner";
IcCompanyNo: Text;
ItemNo: Code[20];
Cust: Record Customer;
ICE: code[15];
UOMcode: Record "Item Unit of Measure";
begin
Clear(ICE);
if Cust.get(SalesHeader."Sell-to Customer No.") then
ICE := Cust.ICE;
if ICPartner.Get(SalesShipmentHeader."Bill-to Customer No.") then
IcCompanyNo := ICPartner.Name
else
Error('No company Exist');
PshipmentLine.Reset();
SalesHeader.Init();
PshipmentLine.SetRange("Document No.", SalesShipmentHeader."No.");
SalesHeader.Validate("Document Type", SalesHeader2."Document Type"::Order);
SalesHeader."No." := '';
SalesHeader.ChangeCompany(IcCompanyNo);
SalesHeader.Insert(true);
Commit();

SalesHeader."Sell-to Customer No." := SalesShipmentHeader."Sell-to Customer No.";
SalesHeader."Bill-to Customer No." := SalesShipmentHeader."Sell-to Customer No.";
// SalesHeader."Sell-to Customer Templ. Code" := 'CLIE000001';
SalesHeader."Salesperson Code" := SalesShipmentHeader."Salesperson Code";
SalesHeader."External Document No." := SalesShipmentHeader."No.";
SalesHeader."IC Direction" := SalesHeader."IC Direction"::Outgoing;
SalesHeader."Send IC Document" := true;
SalesHeader."Document Date" := SalesShipmentHeader."Document Date";
SalesHeader."Posting Date" := SalesShipmentHeader."Posting Date";
SalesHeader."VAT Bus. Posting Group" := SalesShipmentHeader."VAT Bus. Posting Group";
SalesHeader."Gen. Bus. Posting Group" := SalesShipmentHeader."Gen. Bus. Posting Group";
SalesHeader."Due Date" := SalesShipmentHeader."Due Date";
SalesHeader."Shipping No." := SalesShipmentHeader."No.";
SalesHeader."ICE" := ICE;
SalesHeader."Sell-to Customer Name" := SalesShipmentHeader."Sell-to Customer Name";
SalesHeader."Sell-to Address" := SalesShipmentHeader."Sell-to Address";
SalesHeader."Payment Method Code" := SalesShipmentHeader."Payment Method Code";
SalesHeader."Payment Terms Code" := SalesShipmentHeader."Payment Terms Code";
SalesHeader."Location Code" := SalesShipmentHeader."Location Code";
SalesHeader."Shipping Agent Code" := SalesShipmentHeader."Shipping Agent Code";
SalesHeader.Modify(true);
//Commit();
//SalesHeader.SetRange("No.", SalesLine."Document No.");
//SalesHeader.SetRange("No.", SalesLine."Document No.");
if PShipmentLine.FindSet() then begin
repeat
Clear(ItemNo);
SalesLine.Reset();
SalesLine.init;
SalesLine."Document Type" := SalesHeader."Document Type";
SalesLine."Document No." := SalesHeader."No.";
SalesLine."Line No." := PshipmentLine."Line No.";
SalesLine.GetSalesHeader();
SalesLine.validate("Unit of Measure Code", PshipmentLine."Unit of Measure Code");
SalesLine."Unit of Measure" := PshipmentLine."Unit of Measure";
SalesLine.ChangeCompany(IcCompanyNo);
SalesLine.Insert(true);

SalesLine.validate(Type, PshipmentLine.Type);
ItemNo := PshipmentLine."No.";
SalesLine."No." := PshipmentLine."No.";
SalesLine.Validate(Quantity, PshipmentLine.Quantity);
SalesLine.Validate("Qty. to Ship", PshipmentLine.Quantity);
SalesLine.Validate("Unit of Measure", PshipmentLine."Unit of Measure");
Commit();
SalesLine.Description := PshipmentLine.Description;
SalesLine."Description 2" := PshipmentLine."Description 2";
SalesLine."Unit Volume" := PshipmentLine."Unit Volume";
SalesLine."Units per Parcel" := PshipmentLine."Units per Parcel";
SalesLine.PrixTTC := PshipmentLine.PrixTTC;

SalesLine."Line Amount" := PshipmentLine."Item Charge Base Amount";
SalesLine."Location Code" := PshipmentLine."Location Code";
SalesLine."Bill-to Customer No." := SalesHeader."Bill-to Customer No.";
SalesLine.Reserve := SalesLine.Reserve::Always;
SalesLine."Unit Price" := PshipmentLine."Unit Price";
SalesLine."Qty to sale" := PshipmentLine."Qty to sale";
SalesLine."Qty. per Unit of Measure" := PshipmentLine."Qty. per Unit of Measure";


// SalesLine."Drop Shipment" := true;
SalesLine."Sales UoM" := PshipmentLine."Sales UoM";


SalesHeader.Validate(Status, SalesHeader.Status::Released);
SalesHeader.Ship := true;
SalesHeader.Invoice := false;
SalesHeader.Receive := false;

CODEUNIT.RUN(CODEUNIT::"Sales-Post", SalesHeader);
SalesLine.ChangeCompany(IcCompanyNo);
SalesLine.Modify(true);


until PshipmentLine.Next() = 0;
end;
end;

[EventSubscriber(ObjectType::Table, Database::"SALES LINE", 'OnAfterAssignItemUOM', '', false, false)]
local procedure OnAfterAssignItemUOM(var SalesLine: Record "Sales Line"; Item: Record Item; CurrentFieldNo: Integer; xSalesLine: Record "Sales Line")
begin
if xSalesLine."Unit of Measure" <> SalesLine."Unit of Measure" then
SalesLine."Unit of Measure" := 'KG';
Message('rr');
end;

Answers

  • lubostlubost Member Posts: 628
    1. If you use CHANGECOMPANY, i think that you should not use triggers (Insert, Modify, Validate), because any record variable used in triggers has not company changed.
    2. Where is your event raised?
  • souoiksouoik Member Posts: 128
    This code genratio PO and SO whit changcompany, know how çan post auyomatically when generat ths PO ans SO
  • krikikriki Member, Moderator Posts: 9,115
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.