How to display vendor detail from vendor code in report

Hi All,

I am creating new report from two tables Enquiry & Enquiry Line. And Enquiry Line table contain vendor numbers article wise in “Vendor No.” field.

Now i want to print vendor detail on the header of report so i write following code on Enquiry Line - OnAfterGetRecord():-

Enquiry Line - OnAfterGetRecord()

Vendrs.RESET;
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN
vend:=Vendrs.“No.”;
name:=Vendrs.Name;
add:=Vendrs.Address;

Vendrs is a Record type variable of vendor table.

But it is not displaying vendor details in report, pls tell me where i am doing wrong i will be very thankfull to you.

Neel

IF Vendrs.GET THEN;

In Section set your SourceExpr to Vendrs.No., Venrds.Name

Vendrs.RESET;
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN BEGIN
vend:=Vendrs.“No.”;
name:=Vendrs.Name;
add:=Vendrs.Address;

END;

Are you placing the variables in Enquiry dataitem header or Enquiry Line dataitem header?

Dear All,

Lot of thanx for your replies and pls see below screen:-

Report displaying item details that ticked in above screen but it is displaying vendor detail of VEN00040 instead of VEN00038.Pls tell me where i am doing wrong and my code is below:-

Enquiry Line - OnAfterGetRecord()
Vendrs.RESET;
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN BEGIN
vend:=Vendrs.“No.”;
nam:=Vendrs.Name;
ad:=Vendrs.Address;

Enquiry Line, Body (3) - OnPreSection()
IF Print THEN
CurrReport.SHOWOUTPUT(TRUE)
ELSE
CurrReport.SHOWOUTPUT(FALSE);

Thanxxxx

Neel

Dear All,

Lot of thanx for your replies and below is my screen:-

and this report will run when user click on “RFQ Print” button. Report displaying correct item detail that is tick (Print) in above screen but it is displaying wrong vendor detail of VEN00040 instead of VEN00038. My report code is below:-

Enquiry Line - OnAfterGetRecord()
Vendrs.RESET;
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN BEGIN
vend:=Vendrs.“No.”;
nam:=Vendrs.Name;
ad:=Vendrs.Address;

Enquiry Line, Body (3) - OnPreSection()
IF Print THEN
CurrReport.SHOWOUTPUT(TRUE)
ELSE
CurrReport.SHOWOUTPUT(FALSE);

Thanxxx

Neel

Enquiry Line - OnAfterGetRecord()
Vendrs.RESET;
Vendrs.SETRANGE(Print,True);
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN BEGIN
vend:=Vendrs.“No.”;
nam:=Vendrs.Name;
ad:=Vendrs.Address;

END;

If you want to print selected records then you need to filter on print=true also.

Manish,

Thanx for your reply and i tried your code but it is displaying below error:-

0882.Enquiry2.JPG

So i tried :- Vendrs.SETRANGE(“Enquiry Line”.Print,True); it is showing same error .

Then i tried :-

“Enquiry Line”.SETRANGE(Print,TRUE);
Vendrs.RESET;
Vendrs.SETRANGE(Vendrs.“No.”,“Vendor No.”);
IF Vendrs.FIND(’-’) THEN BEGIN
vend:=Vendrs.“No.”;
nam:=Vendrs.Name;
ad:=Vendrs.Address;
END;

but it is displaying detail of first vendor (VEN00040) instead of correct vendor (VEN00038).

Pls suggest me some solution i will be very thankful to you.

Write below code in Enquiry Line - on Pre Dataitem trigger

“Enquiry Line”.SETRANGE(Print,TRUE);

Write below code in Enquiry Line- OnAfterGet record trigger
vend := ‘’;

nam := ‘’;

ad := ‘’;
IF Vendrs.GET(“Vendor No.”) THEN BEGIN
vend:=Vendrs.“No.”;
nam:=Vendrs.Name;
ad:=Vendrs.Address;
END;

You didnt mention where are you showing above fields in sections…

If your report data item is Enquiry Line then set Table Filter in DataItemTableView property.

First of all, your variable names are crap, you need to fix those

  • don’t call it ‘Vendrs’, call it “Vendor”. It’s based on the “Vendor” table, so you need to call it “Vendor” like standard C/AL.
  • don’t call it ‘Vend’, call it “VendorNo”
  • don’t call it ‘Nam’, call it “Name”, or “VendorName”. Why on earth would you leave off just one letter?
  • don’t call it ‘Ad’, call it “Address”, or “VendorAddress”

Unclear variable names make code difficult to read. Programming is hard enough as it is, make it easier on yourself and everyone else after you that has to do maintenance on your code by using variable names that make sense.

You really don’t need to put the field values into variables at all, because you can use Vendor.“No.” directly in SourceExpr.

You have to think about this. The “Vendor No” field stores the primary key value of the Vendor table, so you would never use filters on the Vendor’s “No.” field. You know the primary key value, so you need to GET the Vendor record to be able to access any of the Vendor’s field values. You should be able to do just Vendor.GET(“Enquiry Line”.“Vendor No.”); and then set the SourceExpr of the report controls directly to the Vendor’s field values. Maybe you can check the value in the Vendor No field and do something like this:

IF “Enquiry Line”.“Vendor No.” = ‘’ THEN BEGIN
CLEAR(Vendor);
END ELSE BEGIN
Vendor.GET(“Enquiry Line”.“Vendor No.”);
END;

That way, if the Vendor number is blank, the field values should be blank as well.

Then finally, you need to think about which Enquiry Line you need to look at, and where the Vendor details go. You say it goes into the report’s header, yet you program the Enquiry Line dataitem to retrieve the information. The last one is marked ‘Print’, but it is showing the details for the first line. Think about that. Observe and follow along the thinking. Debug the report and walk through it step by step. Figure out why it is looking at the first one and not the one you need. Think about the control flow of a report object. What happens first, when are sections printed, when is data retrieved. Chances are that you will find that the report header is rendered well before it gets to the right Enquiry Line.

You probably have that code in the wrong place. Maybe the code that retrieves the Vendor information should go somewhere else. Maybe you need to program a new EnquiryLine variable, on which you set a filter on the ‘Print’ field, in order to retrieve the right record, and use the Vendor No on that one.

Mohana Sir,

Lot of Thanxxxxxxxxxxxxxxxxxxx.

Problem solved.

Thanx Again.

Neel

Welcome

Please also use variable names as suggested by Denster…

it might work but it’s not the right solution