Hi everyone,
I want to ask, is there any code i can use to force recalculate line in copy document function. I am not very good at code thing.
Hi everyone,
I want to ask, is there any code i can use to force recalculate line in copy document function. I am not very good at code thing.
There is already an option available to Recalculate Lines in Copy Document Functionality.
Do you mean the same or something else?
Yes the same, except i want it to be always “checked” to avoid user from being forget to do that.
You can write code in beginning OnPreDataitem trigger of report 292 - Copy Sales document (for Sales side) to check whether RecalculateLines variable is TRUE or FALSE and you can show confirmation message whether to continue or not if It is FALSE.
Hi Lie,
If you want that it must be TRUE always, then write code on OnPreReport trigger of report 292.
RecalculateLines := TRUE after SetProperties function
and make Recalculate Lines Check box Un-Editable on request form so that user can’t modify this.
I didnt find onpredataitem trigger this is the only triggers i found in report 292.
Documentation()
Report - OnInitReport()
Report - OnPreReport()
CopyDocMgt.SetProperties(IncludeHeader,RecalculateLines,FALSE,FALSE,FALSE);
CopyDocMgt.CopySalesDoc(DocType,DocNo,SalesHeader)
Report - OnPostReport()
Report - OnCreateHyperlink(VAR URL : Text[1024])
Report - OnHyperlink(URL : Text[1024])
SetSalesHeader(VAR NewSalesHeader : Record “Sales Header”)
SalesHeader := NewSalesHeader;
ValidateDocNo()
IF DocNo = ‘’ THEN
FromSalesHeader.INIT
ELSE
IF FromSalesHeader.“No.” = ‘’ THEN BEGIN
FromSalesHeader.INIT;
CASE DocType OF
DocType::Quote,
DocType::“Blanket Order”,
DocType::Order,
DocType::Invoice,
DocType::“Return Order”,
DocType::“Credit Memo”:
FromSalesHeader.GET(CopyDocMgt.SalesHeaderDocType(DocType),DocNo);
DocType::“Posted Shipment”:
BEGIN
FromSalesShptHeader.GET(DocNo);
FromSalesHeader.TRANSFERFIELDS(FromSalesShptHeader);
END;
DocType::“Posted Invoice”:
BEGIN
FromSalesInvHeader.GET(DocNo);
FromSalesHeader.TRANSFERFIELDS(FromSalesInvHeader);
END;
DocType::“Posted Return Receipt”:
BEGIN
FromReturnRcptHeader.GET(DocNo);
FromSalesHeader.TRANSFERFIELDS(FromReturnRcptHeader);
END;
DocType::“Posted Credit Memo”:
BEGIN
FromSalesCrMemoHeader.GET(DocNo);
FromSalesHeader.TRANSFERFIELDS(FromSalesCrMemoHeader);
END;
END;
END;
FromSalesHeader.“No.” := ‘’;
IncludeHeader :=
(DocType IN [DocType::“Posted Invoice”,DocType::“Posted Credit Memo”]) AND
((DocType = DocType::“Posted Credit Memo”) <>
(SalesHeader.“Document Type” IN
[SalesHeader.“Document Type”::“Return Order”,SalesHeader.“Document Type”::“Credit Memo”])) AND
(SalesHeader.“Bill-to Customer No.” IN [FromSalesHeader.“Bill-to Customer No.”,’’]);
ValidateIncludeHeader;
LookupDocNo()
CASE DocType OF
DocType::Quote,
DocType::“Blanket Order”,
DocType::Order,
DocType::Invoice,
DocType::“Return Order”,
DocType::“Credit Memo”:
BEGIN
FromSalesHeader.FILTERGROUP := 0;
FromSalesHeader.SETRANGE(“Document Type”,CopyDocMgt.SalesHeaderDocType(DocType));
IF SalesHeader.“Document Type” = CopyDocMgt.SalesHeaderDocType(DocType) THEN
FromSalesHeader.SETFILTER(“No.”,’<>%1’,SalesHeader.“No.”);
FromSalesHeader.FILTERGROUP := 2;
FromSalesHeader.“Document Type” := CopyDocMgt.SalesHeaderDocType(DocType);
FromSalesHeader.“No.” := DocNo;
IF (DocNo = ‘’) AND (SalesHeader.“Sell-to Customer No.” <> ‘’) THEN
IF FromSalesHeader.SETCURRENTKEY(“Document Type”,“Sell-to Customer No.”) THEN BEGIN
FromSalesHeader.“Sell-to Customer No.” := SalesHeader.“Sell-to Customer No.”;
IF FromSalesHeader.FIND(’=><’) THEN;
END;
IF FORM.RUNMODAL(0,FromSalesHeader) = ACTION::LookupOK THEN
DocNo := FromSalesHeader.“No.”;
END;
DocType::“Posted Shipment”:
BEGIN
FromSalesShptHeader.“No.” := DocNo;
IF (DocNo = ‘’) AND (SalesHeader.“Sell-to Customer No.” <> ‘’) THEN
IF FromSalesShptHeader.SETCURRENTKEY(“Sell-to Customer No.”) THEN BEGIN
FromSalesShptHeader.“Sell-to Customer No.” := SalesHeader.“Sell-to Customer No.”;
IF FromSalesShptHeader.FIND(’=><’) THEN;
END;
IF FORM.RUNMODAL(0,FromSalesShptHeader) = ACTION::LookupOK THEN
DocNo := FromSalesShptHeader.“No.”;
END;
DocType::“Posted Invoice”:
BEGIN
FromSalesInvHeader.“No.” := DocNo;
IF (DocNo = ‘’) AND (SalesHeader.“Sell-to Customer No.” <> ‘’) THEN
IF FromSalesInvHeader.SETCURRENTKEY(“Sell-to Customer No.”) THEN BEGIN
FromSalesInvHeader.“Sell-to Customer No.” := SalesHeader.“Sell-to Customer No.”;
IF FromSalesInvHeader.FIND(’=><’) THEN;
END;
IF FORM.RUNMODAL(0,FromSalesInvHeader) = ACTION::LookupOK THEN
DocNo := FromSalesInvHeader.“No.”;
END;
DocType::“Posted Return Receipt”:
BEGIN
FromReturnRcptHeader.“No.” := DocNo;
IF (DocNo = ‘’) AND (SalesHeader.“Sell-to Customer No.” <> ‘’) THEN
IF FromReturnRcptHeader.SETCURRENTKEY(“Sell-to Customer No.”) THEN BEGIN
FromReturnRcptHeader.“Sell-to Customer No.” := SalesHeader.“Sell-to Customer No.”;
IF FromReturnRcptHeader.FIND(’=><’) THEN;
END;
IF FORM.RUNMODAL(0,FromReturnRcptHeader) = ACTION::LookupOK THEN
DocNo := FromReturnRcptHeader.“No.”;
END;
DocType::“Posted Credit Memo”:
BEGIN
FromSalesCrMemoHeader.“No.” := DocNo;
IF (DocNo = ‘’) AND (SalesHeader.“Sell-to Customer No.” <> ‘’) THEN
IF FromSalesCrMemoHeader.SETCURRENTKEY(“Sell-to Customer No.”) THEN BEGIN
FromSalesCrMemoHeader.“Sell-to Customer No.” := SalesHeader.“Sell-to Customer No.”;
IF FromSalesCrMemoHeader.FIND(’=><’) THEN;
END;
IF FORM.RUNMODAL(0,FromSalesCrMemoHeader) = ACTION::LookupOK THEN
DocNo := FromSalesCrMemoHeader.“No.”;
END;
END;
ValidateDocNo;
Sorry, it is Report-onPreReport trigger and not OnPreDataItem trigger
Yes i have written some code there and it works.
It seems there is also another way. If user want particular type of document always recalculate lines, a little addition on this line could come handy
ValidateIncludeHeader()
RecalculateLines :=
(DocType IN [DocType::“Posted Shipment”,
DocType::“Posted Return Receipt”,
DocType::Order,
DocType::“Posted Invoice”,
DocType::“Credit Memo”,
DocType::“Posted Credit Memo”,
DocType::“Return Order”])
OR NOT IncludeHeader;