how to skip the loop if same invoice id in purchase register report in ax 2009

In purchase register report, im displaying all the invoice lines.

I have included one column called Roundoff(invoice round off amount). this should display for only one line of an invoice.

for e.g:

VocherId Invoice ID ItemCode Roundoff TotValue
VC-00001 INV-001 ITM-001 0.50 120.50
VC-00001 INV-001 ITM-002 0.00 146.00
VC-00001 INV-001 ITM-003 0.00 221.00
VC-00002 INV-002 ITM-002 0.25 175.75
VC-00002 INV-002 ITM-003 0.00 167.00

How to achieve this through x++ code in report.

Note: the round off is the display method.

Any help would be appreciated.

Thanks in advance.

well … where you stuck…write display method…

Hi Krishna,

thank you for ur reply.

Actually im very new to AX.

i dont know what to write in display method.

this is my code i already written in display method to get round off, but it display for all the line for the same invoice.

display AmountMst roundOff()

{

AmountMst totalValueINR;

return vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId, vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup, vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

}

Please help me to solve this issue,.

How will you decide which line should show the value? Has the line a specific flag or something?

Hi martin,

Thanks for the reply.

there no specific flag for the line…

i want to display any one of the line for the invoice.

for e.g: if the invoice has 4 lines, i want to show the roundoff value to anyone of the line for that invoice.

Are you saying that you want to show the value for one random line and show zero for the remaining three lines? It’s a suspicious design decision, but it surely can be implemented.

For example, you can write the display method on the reprort and remember whether you already set it the value for a particular invoice (e.g. by storing InvoiceId in a Set).

Hi Martin,

Yes,you are coorect.

i want to show the value for one random line and show zero for the remaining three lines.

Im very new to AX. I hve experience in MSD Navision. Now i migratred to AX.

so im not good at X++ now.So, can please tell me the code for the above scenario …

Thanks.

If you want to follow my suggestion (although you can do it in many different ways), use the Set class to store Invoice IDs. Use the add() method to add an invoice ID to the set and in() method to check whether it’s already there (= that you’ve already processed the invoice). You can even simplify it by using add() only and checking its return value.

This is nothing too specific to AX; I assume that NAV has some collection classes as well.

Hi Martin,

InvoiceId in report is an display method.

can u give me example code please.

Sorry, I’m not going to do the whole thing for you. But feel free to ask if you don’t understand something and can’t figure it by yourself (with the help of AX documentation and internet).

Whether you get invoice ID from a field or a display method is irrelevant. As soon as you have the ID, you can work with it as described above.

1)AmountMst roundOffval ;//declare variable in classdeclaration fot report

2)in execute section method of body

invoicenum invoiceIdNew,invoiceIdOld;

invoiceIdNew = vendinvoicetrans.InvoiceId;

roundOffval = 0;

if (invoiceIdNew != invoiceIdOld)

{

roundOffval = vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId, vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup, vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

}

super();

invoiceIdOld = invoiceIdNew ;

3)display method

display AmountMst roundOff()

{

return roundOffval ;

}

Hi Krishna,

thank you for ur help,

there is another code written in esecution method.

void executeSection()

{;

if (!reportStringControlName)

{

reportStringControlName = this.control(fieldnum(VendInvoiceTrans,Name));

}

if (reportStringControlName)

{

reportStringControlName.height100mm(reportStringControlName.heightOfWordWrappedString100mm(vendInvoiceTrans.Name));

}

super();

}

how can i write the code you gave in that method.

void executeSection()

{

invoicenum invoiceIdNew,invoiceIdOld;//added

;

//new code added

invoiceIdNew = vendinvoicetrans.InvoiceId;

roundOffval = 0;

if (invoiceIdNew != invoiceIdOld)

{

roundOffval = vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId, vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup, vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

}

//end

if (!reportStringControlName)

{

reportStringControlName = this.control(fieldnum(VendInvoiceTrans,Name));

}

if (reportStringControlName)

{

reportStringControlName.height100mm(reportStringControlName.heightOfWordWrappedString100mm(vendInvoiceTrans.Name));

}

super();

invoiceIdOld = invoiceIdNew ;//newly added

}

Hi Krishna,

Yes i added how you said and compiled with no errors.

Still the roundoff value is showing in all the lines for the same invoice.

I have done exactly what you said.

  1. Declared a variable in ClassDeclaration.

  2. added a code in ExecutionSection

3)return a value in Display method.

thanks.

show your code which you written…

1) ClassDeclaration

public class ReportRun extends ObjectRun

{

ReportStringControl reportStringControlName;

TaxSpec taxSpec;

VendInvoiceTrans vendInvoiceTrans;

TaxTrans taxTrans;

boolean firstPage;

boolean firstVendInvoiceJour;

DialogField dialogNewpage;

AmountMst roundOffval ; //RoundOff

NoYes newPage;

2)Body- ExecuteSection()

void executeSection()

{

VendinvoiceId invoiceIdNew,invoiceIdOld; //Roundoff

;

invoiceIdNew = vendinvoicetrans.InvoiceId; //RoundOff

roundOffval = 0; //RoundOff

if (invoiceIdNew != invoiceIdOld)

{

roundOffval = vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId,vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup,vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

} //roundOff

if (!reportStringControlName)

{

reportStringControlName = this.control(fieldnum(VendInvoiceTrans,Name));

}

if (reportStringControlName)

{

reportStringControlName.height100mm(reportStringControlName.heightOfWordWrappedString100mm(vendInvoiceTrans.Name));

}

super();

invoiceIdOld = invoiceIdNew ; //roundoff

}

3) Display Method:

Display AmountMst roundOff()

{

return roundOffval ;

}

then you need to debug the code…

1) ClassDeclaration

public class ReportRun extends ObjectRun

{

ReportStringControl reportStringControlName;

TaxSpec taxSpec;

VendInvoiceTrans vendInvoiceTrans;

TaxTrans taxTrans;

boolean firstPage;

boolean firstVendInvoiceJour;

DialogField dialogNewpage;

AmountMst roundOffval ; //RoundOff

NoYes newPage;

2)Body - ExecuteSection()

void executeSection()

{

VendinvoiceId invoiceIdNew,invoiceIdOld; //Roundoff

;

invoiceIdNew = vendinvoicetrans.InvoiceId; //RoundOff

roundOffval = 0; //RoundOff

if (invoiceIdNew != invoiceIdOld)

{

roundOffval = vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId,vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup,vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

} //roundOff

if (!reportStringControlName)

{

reportStringControlName = this.control(fieldnum(VendInvoiceTrans,Name));

}

if (reportStringControlName)

{

reportStringControlName.height100mm(reportStringControlName.heightOfWordWrappedString100mm(vendInvoiceTrans.Name));

}

super();

invoiceIdOld = invoiceIdNew ; //roundoff

}

3) Display Method()

Display AmountMst roundOff()

{

return roundOffval ;

}

Hi Krishna,

I debugged the code.

the “invoiceIdOld” is empty when it coming to loop.

E.g: i have 3 lines for an invoice.

while coming to the loop 2nd time the invoiceOld is Empty, so it always true for this condition:

IF (invoiceIdOld != invoiceIdNew)

So, it goes inside the “if” condition.

so it displays the round off value for all the lines.

ok. change the code in executesection method and try like below(i.e just add line of code before super nvoiceIdOld = invoiceIdNew ;//newly added)…

void executeSection()

{

invoicenum invoiceIdNew,invoiceIdOld;//added

;

//new code added

invoiceIdNew = vendinvoicetrans.InvoiceId;

roundOffval = 0;

if (invoiceIdNew != invoiceIdOld)

{

roundOffval = vendInvoiceJour::findFromVendInvoiceTrans(vendinvoicetrans.PurchID, vendinvoicetrans.InvoiceId, vendinvoicetrans.InvoiceDate, vendinvoicetrans.numberSequenceGroup, vendinvoicetrans.InternalInvoiceId).InvoiceRoundOff;

}

//end

if (!reportStringControlName)

{

reportStringControlName = this.control(fieldnum(VendInvoiceTrans,Name));

}

if (reportStringControlName)

{

reportStringControlName.height100mm(reportStringControlName.heightOfWordWrappedString100mm(vendInvoiceTrans.Name));

}

invoiceIdOld = invoiceIdNew ;//newly added

super();

}