ALAppExtensions
ALAppExtensions copied to clipboard
Table 5050 Contact - OnValidate Company No.
Hi Al-team,
ss it intended that the key is placed on other fields than those to be filtered?
field(5051; "Company No."; Code[20])
{
Caption = 'Company No.';
TableRelation = Contact WHERE(Type = CONST(Company));
trigger OnValidate()
var
Opp: Record Opportunity;
OppEntry: Record "Opportunity Entry";
Task: Record "To-do";
InteractLogEntry: Record "Interaction Log Entry";
SegLine: Record "Segment Line";
SalesHeader: Record "Sales Header";
Cont: Record Contact;
ContBusRel: Record "Contact Business Relation";
begin
if Cont.Get("Company No.") then
InheritCompanyToPersonData(Cont)
else
Clear("Company Name");
if "Company No." = xRec."Company No." then
exit;
TestField(Type, Type::Person);
SegLine.SetRange("Contact No.", "No.");
if not SegLine.IsEmpty then
Error(Text012, FieldCaption("Company No."));
if Cont.Get("No.") then begin
if xRec."Company No." <> '' then begin
Opp.SetCurrentKey("Contact Company No.", "Contact No.");
Opp.SetRange("Contact Company No.", xRec."Company No.");
Opp.SetRange("Contact No.", "No.");
if not Opp.IsEmpty then
Opp.ModifyAll("Contact No.", xRec."Company No.");
OppEntry.SetCurrentKey("Contact Company No.", "Contact No.");
OppEntry.SetRange("Contact Company No.", xRec."Company No.");
OppEntry.SetRange("Contact No.", "No.");
if not OppEntry.IsEmpty then
OppEntry.ModifyAll("Contact No.", xRec."Company No.");
Task.SetCurrentKey("Contact Company No.", "Contact No.");
Task.SetRange("Contact Company No.", xRec."Company No.");
Task.SetRange("Contact No.", "No.");
if not Task.IsEmpty then
Task.ModifyAll("Contact No.", xRec."Company No.");
InteractLogEntry.SetCurrentKey("Contact Company No.", "Contact No.");
InteractLogEntry.SetRange("Contact Company No.", xRec."Company No.");
InteractLogEntry.SetRange("Contact No.", "No.");
if not InteractLogEntry.IsEmpty then
InteractLogEntry.ModifyAll("Contact No.", xRec."Company No.");
ContBusRel.Reset;
// NEW >>>>
// ContBusRel.SetCurrentKey("Link to Table", "No.");
ContBusRel.SetCurrentKey("Link to Table", "Contact No.");
// NEW <<<<
ContBusRel.SetRange("Link to Table", ContBusRel."Link to Table"::Customer);
ContBusRel.SetRange("Contact No.", xRec."Company No.");
SalesHeader.SetCurrentKey("Sell-to Customer No.", "External Document No.");
SalesHeader.SetRange("Sell-to Contact No.", "No.");
if ContBusRel.FindFirst then
SalesHeader.SetRange("Sell-to Customer No.", ContBusRel."No.")
else
SalesHeader.SetRange("Sell-to Customer No.", '');
if SalesHeader.Find('-') then
repeat
SalesHeader."Sell-to Contact No." := xRec."Company No.";
if SalesHeader."Sell-to Contact No." = SalesHeader."Bill-to Contact No." then
SalesHeader."Bill-to Contact No." := xRec."Company No.";
SalesHeader.Modify;
until SalesHeader.Next = 0;
SalesHeader.Reset;
SalesHeader.SetCurrentKey("Bill-to Contact No.");
SalesHeader.SetRange("Bill-to Contact No.", "No.");
if not SalesHeader.IsEmpty then
SalesHeader.ModifyAll("Bill-to Contact No.", xRec."Company No.");
end else begin
Opp.SetCurrentKey("Contact Company No.", "Contact No.");
Opp.SetRange("Contact Company No.", '');
Opp.SetRange("Contact No.", "No.");
if not Opp.IsEmpty then
Opp.ModifyAll("Contact Company No.", "Company No.");
OppEntry.SetCurrentKey("Contact Company No.", "Contact No.");
OppEntry.SetRange("Contact Company No.", '');
OppEntry.SetRange("Contact No.", "No.");
if not OppEntry.IsEmpty then
OppEntry.ModifyAll("Contact Company No.", "Company No.");
Task.SetCurrentKey("Contact Company No.", "Contact No.");
Task.SetRange("Contact Company No.", '');
Task.SetRange("Contact No.", "No.");
if not Task.IsEmpty then
Task.ModifyAll("Contact Company No.", "Company No.");
InteractLogEntry.SetCurrentKey("Contact Company No.", "Contact No.");
InteractLogEntry.SetRange("Contact Company No.", '');
InteractLogEntry.SetRange("Contact No.", "No.");
if not InteractLogEntry.IsEmpty then
InteractLogEntry.ModifyAll("Contact Company No.", "Company No.");
end;
if CurrFieldNo <> 0 then
Modify;
end;
end;
Hi, the same behavior is used in the function CreateCustomerLink
Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. We will update this issue with information about availability.