How to Add a Source Doc to a Warehouse Receipt..?

thetallblokethetallbloke Member Posts: 66
Hi guys,

On the Warehouse Receipt form (5768), under the Functions menu, there is an option to "Get Source Documents"..

From a code unit, I have a situation where I know what the document is that I want to add and its document type.. What I want to do, is run the "Get Source Documents" function, but skip the actual document selection bit of the process..

I've followed the code through to Code unit 5751 (Get Source Doc. Inbound), to the GetSingleInboundDoc function.. but it doesn't make sense to me...

There isn't anything obvious that says "read these lines from this source document and try to add them to the warehouse receipt"...

Have I followed the code wrong..??? is it done elsewhere..??? I'm at a loss..

Any help to point me in the right direction would be very much appreciated..


Thanks
.
I'm not crazy !!! Just ask my toaster...
.

Answers

  • ara3nara3n Member Posts: 9,256
    Your code should looks something like this.

     WhseReceiptHeader.get(YourWarehouseNo);
      GetSourceDocuments.SetOneCreatedReceiptHeader(WhseReceiptHeader);
      WhseRqst.setrange("source No.", YouPONumber);
    
      PurchaseLine.setrange("Document No.",YouPONumber);
      PurchaseLine.setrange("Document type",PurchaseLine."Document type"::Order);
    
      GetSourceDocuments.USEREQUESTFORM(FALSE);
      GetSourceDocuments.SETTABLEVIEW(WhseRqst);
     GetSourceDocuments..SETTABLEVIEW(PurchaseLine);
      GetSourceDocuments.RUNMODAL;
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • thetallblokethetallbloke Member Posts: 66
    Thanks heaps Ara3n...!!!

    I was able to take that code and modify it slightly to do exactly what I needed...

    Tell me if I did something wrong... Basically, I'm passing in:
      ReceiptNo - Blank means 'create a new one' otherwise find the existing one.
      DocumentNo (document to add to the receipt, PO/SRO/TRANS)
      DocumentType

    IF ReceiptNo = '' THEN BEGIN
      //Create a new ReceiptHeader
      WhseReceiptHeader.INIT();
      WhseReceiptHeader.INSERT(TRUE);
      ReceiptNo := WhseReceiptHeader."No.";
    END ELSE BEGIN
      WhseReceiptHeader.SETRANGE("No.", ReceiptNo);
    END;
    
    GetSourceDocuments.SetOneCreatedReceiptHeader(WhseReceiptHeader);
    
    WhseRqst.SETRANGE("Source No.", DocumentNo); //YouPONumber);
    
    //0 - Purchase Order
    //1 - Purchase Return Order
    //2 - Sales Order
    //3 - Sales Return Order
    //4 - Transfer Order
    
    IF (DocumentType = 0) THEN BEGIN
    // 39 for PO/PRO
      WhseRqst.SETRANGE("Source Type", 39);
      PurchaseLine.SETRANGE("Document No.", DocumentNo); //YouPONumber);
      PurchaseLine.SETRANGE("Document Type", PurchaseLine."Document Type"::Order);
    //  PurchaseLine.SETRANGE("Document type", PurchaseLine."Document Type"::"Return Order");
    END ELSE BEGIN
    // 37 for SO/SRO
      WhseRqst.SETRANGE("Source Type", 37);
      SalesLine.SETRANGE("Document No.", DocumentNo); //YourSONumber);
      SalesLine.SETRANGE("Document Type", SalesLine."Document Type"::Order);
    END;
    
    GetSourceDocuments.USEREQUESTFORM(FALSE);
    GetSourceDocuments.SETTABLEVIEW(WhseRqst);
    
    IF DocumentType = 37 THEN
      GetSourceDocuments.SETTABLEVIEW(PurchaseLine)
    ELSE
      GetSourceDocuments.SETTABLEVIEW(SalesLine);
    
    GetSourceDocuments.RUNMODAL;
    

    Actually, looking at the code now, I haven't catered for transfers, but I will do that shortly..

    Thanks
    .
    I'm not crazy !!! Just ask my toaster...
    .
  • ara3nara3n Member Posts: 9,256
    I would change the code so that you don't hardcode table no.

    Instead use Database::"Sales Line",

    same for document type
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • thetallblokethetallbloke Member Posts: 66
    Thanks..

    I will make those changes...
    .
    I'm not crazy !!! Just ask my toaster...
    .
Sign In or Register to comment.