auto open purchase order

Hi Friends,

I’m creating a new report module.there is vendor numbers on the order line , for example 4 line has same vendor number and sixth line has different vendor number acording to first 4 line.what I try to do is creating a purchasing order for this order.Normaly If there is 2 diffrent vendor number on the order , we create 2 different purchasing order.I want to make them just 1.2 different vendor number and just 1 purchasing order for them

So I try this but system just create purchasing order for first line , I can’t create PO for rest of different vendor can I do that ? I need help

Sales Line

Line No Vendor No Item No

1 10 Item1

2 10 Item2

3 10 Item3

4 20 Item4

5 10 Item5

Created Purchase Order: Vendor No: 10

Line No Item No

1 Item1

2 Item2

3 Item3

4 Item5

Sales Header - OnAfterGetRecord()





IF “Sales Line”.“Vendor No Line” = PurchaseHeader.“Buy-from Vendor No.” THEN BEGIN




MESSAGE(“Sales Line”.“No.”);

UNTIL “Sales Line”.NEXT = 0;


UNTIL “Sales Line”.NEXT = 0;




PurchaseHeader.“Document Type”:=PurchaseHeader.“Document Type”::Order;

PurchaseHeader.VALIDATE(“Posting Date”,OrderDate);

PurchaseHeader.VALIDATE(“Order Date”,OrderDate);

PurchaseHeader.VALIDATE(“Document Date”,OrderDate);

PurchaseHeader.VALIDATE(“Expected Receipt Date”,“Sales Header”.“Requested Delivery Date”);

PurchaseHeader.VALIDATE(“Prepayment Due Date”,OrderDate);

PurchaseHeader.VALIDATE(“Buy-from Vendor No.”,VendorNo);




“Sales Line”.SETFILTER(“Sales Line”.“Vendor No Line”, PurchaseHeader.“Buy-from Vendor No.”);

PurchaseLine.VALIDATE(“Document Type”,PurchaseHeader.“Document Type”);

PurchaseLine.VALIDATE(“Document No.”,PurchaseHeader.“No.”);

PurchaseLine.VALIDATE(“Line No.”,“Sales Line”.“Line No.”);

PurchaseLine.VALIDATE(Type,“Sales Line”.Type);

PurchaseLine.VALIDATE(“No.”,“Sales Line”.“No.”);

PurchaseLine.VALIDATE(“Variant Code”,“Sales Line”.“Variant Code”);

PurchaseLine.VALIDATE(“Revision No.”,“Sales Line”.“Revision No.”);

PurchaseLine.VALIDATE(“Brand Code”,“Sales Line”.“Brand Code”);

PurchaseLine.VALIDATE(“Location Code”,“Sales Line”.“Location Code”);

PurchaseLine.VALIDATE(Quantity,“Sales Line”.Quantity);

PurchaseLine.VALIDATE(PurchaseLine.Reference,“Sales Line”.Reference);

PurchaseLine.VALIDATE(PurchaseLine.Notes,“Sales Line”.Notes);

“Sales Line”.“Purchase No”:=PurchaseHeader.“No.”;


Just so I understand your question completely, your goal is to create one Purchase Order for each vendor in the list of vendors on the sales lines, and then add each sales line to the right new PO according to vendor, is that right?

So according to your example, the end result would be 1 PO for vendor 10, with 4 lines, and 1 PO for vendor 20, with 1 line. Is that what you’re trying to do?

Hi ,

Thank you for your support …

Yes , this is what I try to do … System just can create PO for first line ( vendor 10 ) , can’t create PO for vendor 20

I guess system cannot see vendor 20

If you’ll notice the second line of your PurchaseL function, you’re filtering the sales line so that the only records in the set are those that have a value in “Vendor No Line” that matches the value in Purchase Header that you created in the 3rd line of your AfterGetRecord code. Because of this filter, the loop that calls your PurchaseL function will be working on a SalesLine record set that does not include the 4th Sales Line that is for vendor 20.

So, that’s the first issue I can see for the fact that you’re only getting one PO out of the process. There are many others. Rather than trying to get that code running through dialog here, maybe you could contemplate the question of how to produce multiple POs from lines that involve different vendors. One approach would be to process the sales line in sets, one set for each vendor. This would suggest that you start with a known list of all the vendors associated with the lines in the sales order you’re working with. Another approach would be to process the sales line in sequence, from top to bottom, one at a time, and have a plan for reacting to the fact that the vendor number could change from one line to the next. What do you want your application to do when it comes upon a new vendor number while looping through the sales lines?

So, I know I haven’t given you a complete set of code that will do what you’re trying to do. But, I have found an obvious bug in the code you’re working with, which I hope will help you. And, I’ve offered some food for thought, which may lead you to rethink the design for the whole process.


After we have done below , we created PO for each line automaticly as PO0001 as you can see below.This is what we can do at the moment.I want system to create PO for line 4. If there is 2 different vendor number in the sales order , system should create 2 different PO. If 5 , there sould be 5 PO . Am I clear here ?

The other thing is ; If there is any empty line in the sales order system should try to create PO for empty line … It should repeat itself continiously until there isn’t any empty line . PurchaseH; needs to look PO number column and be sure that all sales line has PO .

Sales Line

Line No Vendor No Item No PO Number

1 10 Item1 PO0001

2 10 Item2 PO0001

3 10 Item3 PO0001

4 20 Item4 (System can’t create PO for this line as its vendor number different.system should be create PO for this line )

5 10 Item5 PO0001

You were perfectly clear the first time, and I do appreciate your effort to be even more so. With all this information, it’s still the case that your current version of the code won’t process line 4 of the sales order because you’re filtering it out of the set with your setfilter command in your PurchaseL function. Fixing that problem is necessary to accomplish your objective, although it is not sufficient. That means that you need to fix this problem, but once you do, you will face other problems as well.

And just to give you a general sense of the nature and function of this forum, we offer advice, observations, we answer questions, and sometimes we try to help debug your code. You’ll generally not find us though offering to write or re-write code for you.

I hope that’s helpful in many ways. If not, at least know that that was my intent.


How do you think I should follow a path? Where I’m making a mistake? Can you help me in how to start making?

did you try PurchaseLine.RESET; before UNTIL “Sales Line”.NEXT = 0; ??

I believe you still have the filters set for first vendor… in PurchaseL() … “Sales Line”.SETFILTER(“Sales Line”.“Vendor No Line”, PurchaseHeader.“Buy-from Vendor No.”);