ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Table 27 Item - Multiple events

Open samra-singhammer opened this issue 4 years ago • 3 comments

It should be possible to extend the CheckDocuments() procedure in order to add an additional check on custom fields from different apps. Currently, it only prevents change of field Type. Please add a publisher in the following procedure as in the example: CheckBOM(CurrFieldNo); CheckPurchLine(CurrFieldNo); CheckSalesLine(CurrFieldNo); CheckProdOrderLine(CurrFieldNo); CheckProdOrderCompLine(CurrFieldNo); CheckPlanningCompLine(CurrFieldNo); CheckTransLine(CurrFieldNo); CheckServLine(CurrFieldNo); CheckProdBOMLine(CurrFieldNo); CheckServContractLine(CurrFieldNo); CheckAsmHeader(CurrFieldNo); CheckAsmLine(CurrFieldNo); CheckJobPlanningLine(CurrFieldNo);

Example:

    local procedure CheckPurchLine(CurrFieldNo: Integer)
    var
        PurchaseLine: Record "Purchase Line";
    begin
        PurchaseLine.SetCurrentKey(Type, "No.");
        PurchaseLine.SetRange(Type, PurchaseLine.Type::Item);
        PurchaseLine.SetRange("No.", "No.");
        if PurchaseLine.FindFirst() then begin
            if CurrFieldNo = 0 then
                Error(Text000, TableCaption, "No.", PurchaseLine."Document Type");
            if CurrFieldNo = FieldNo(Type) then
                Error(CannotChangeFieldErr, FieldCaption(Type), TableCaption, "No.", PurchaseLine.TableCaption);
            **OnAfterFindPurchaseLineOnCheckPurchLine(CurrFieldNo);**
        end;
    end;
[IntegrationEvent(false, false)]
local procedure OnAfterFindPurchaseLineOnCheckPurchLine(CurrFieldNo: Integer)
begin
end;

samra-singhammer avatar Oct 05 '22 07:10 samra-singhammer

There is already OnAfterCheckDocuments(Rec, xRec, CurrFieldNo); where you can add all the checks you want, can you use that? It's much preferable than adding so many events for the same purpose.

Vadim-Stepanenko avatar Oct 13 '22 10:10 Vadim-Stepanenko

Well, we are trying not to copy the same code as in BaseApp multiple times. For example, we would have to add the same procedures (the ones that I listed above) and add the same checks as in BaseApp just to be able to check field that is not Type. Is there a way you can make standard procedures more generic, something like:

local procedure CheckPurchLine(CurrFieldNo: Integer; **FieldNo: Integer; FieldCaption: Text**)
    var
        PurchaseLine: Record "Purchase Line";
    begin
        PurchaseLine.SetCurrentKey(Type, "No.");
        PurchaseLine.SetRange(Type, PurchaseLine.Type::Item);
        PurchaseLine.SetRange("No.", "No.");
        if PurchaseLine.FindFirst() then begin
            if CurrFieldNo = 0 then
                Error(Text000, TableCaption, "No.", PurchaseLine."Document Type");
            if CurrFieldNo = **FieldNo** then
                Error(CannotChangeFieldErr, **FieldCaption**, TableCaption, "No.", PurchaseLine.TableCaption);
        end;
    end;

In this way we could just pass the parameters we want to be compared.

samra-singhammer avatar Oct 13 '22 11:10 samra-singhammer

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. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

Build ID: 51281.

JesperSchulz avatar Dec 23 '22 11:12 JesperSchulz