Show the attached documents based on Lot numbers in posted sales invoice

I have attached a document on the purchase line (standard feature) with respect to LOT number. All the items has item tracking enabled and lot number is required. So each line in PO is mandatory to attach one document. So once the document is posted, the same attached will be copied to posted purchase invoice.

So the issue I’m trying to solve is I have to show the same document when I create a sales order with the same item and select the same lot the attached which is attached in the posted purchase document should be shown when a sales order is creating for that particular lot and item combination and once the sales order is posted it should be copied to posted sales invoice too. May I know what is the best way to solve it?

I’m thinking to flow the attachments to Item ledger entry once the purchase order is posted and fetch from there when we’re creating sales order and selecting the lot.

You can flow the document thru the Lot no. Information card, and then when the Lot is associated to a sales order, have it transfer upon assignment of a SO.

Attachments are not natively part of the Lot no information, but it can possibly be added. That way if the attachment is associated with the lot number that is where you would find it.

1 Like
  1. Thankyou so much for responding. Yes, I was thinking about that solution and added attachments in the lot information card, but I’ve some concerns.
  2. Firstly attachment should be mandatory without it if I’m trying to post PO it should give error but Lot Info card will be created on receiving the item, so is there any change that I can check before receiving it?
  3. Secondly, the size of the database will be increased because every PO line has one COA document. How to manage that? (I’ve thought of using sharepoint for that but if you’ve any idea it would be helpful)

I’ve used below codeunit but it always shows the same document I’ve attached for one LOT Info I think there I’m doing something wrong in the “OnBeforeDrillDown” event.

codeunit 50100 DocumentAttachment
{
    [EventSubscriber(ObjectType::Page, Page::"Document Attachment Factbox", 'OnBeforeDrillDown', '', false, false)]
    local procedure OnBeforeDrillDown(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
    var
        LotNoInfo: Record "Lot No. Information";
    begin
        case DocumentAttachment."Table ID" of
            DATABASE::"Lot No. Information":
                begin
                    RecRef.Open(DATABASE::"Lot No. Information");
                    LotNoInfo.SetRange("Item No.", DocumentAttachment."No.");
                    if LotNoInfo.FindFirst() then
                        RecRef.GetTable(LotNoInfo);
                end;
        end;
    end;

    [EventSubscriber(ObjectType::Page, Page::"Document Attachment Details", 'OnAfterOpenForRecRef', '', false, false)]
    local procedure OnAfterOpenForRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef; var FlowFieldsEditable: Boolean);
    var
        FieldRef: FieldRef;
        ItemNo: Code[20];
        Variant: Code[10];
        LotNo: Code[50];
    begin
        case RecRef.Number of
            DATABASE::"Lot No. Information":
                begin
                    FieldRef := RecRef.Field(1);
                    ItemNo := FieldRef.Value;
                    DocumentAttachment.SetRange("No.", ItemNo);

                    FieldRef := RecRef.Field(2);
                    Variant := FieldRef.Value;
                    DocumentAttachment.SetRange("Lot Variant", Variant);

                    FieldRef := RecRef.Field(3);
                    LotNo := FieldRef.Value;
                    DocumentAttachment.SetRange("Lot Number", LotNo);

                    FlowFieldsEditable := false;

                end;
        end;
    end;

    [EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', false, false)]
    local procedure OnAfterInitFieldsFromRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
    var
        FieldRef: FieldRef;
        ItemNo: Code[20];
        Variant: Code[10];
        LotNo: Code[50];
    begin
        case RecRef.Number of
            DATABASE::"Lot No. Information":
                begin
                    FieldRef := RecRef.Field(1);
                    ItemNo := FieldRef.Value;
                    DocumentAttachment.Validate("No.", ItemNo);

                    FieldRef := RecRef.Field(2);
                    Variant := FieldRef.Value;
                    DocumentAttachment.Validate("Lot Variant", Variant);

                    FieldRef := RecRef.Field(3);
                    LotNo := FieldRef.Value;
                    DocumentAttachment.Validate("Lot Number", LotNo);
                    DocumentAttachment.Validate("Document Type", Enum::"Attachment Document Type"::"Lot Info");
                end;
        end;
    end;
}