Discussion:
Print Purchase Order to PDF with X++
(too old to reply)
Eduardo
2010-09-14 18:12:03 UTC
Permalink
Hi,

I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)

I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)

The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.

I encounter an error here:

protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query

//reportName = PurchPurchaseOrder
report = new Report(reportName);

// get the Report Query def into query obj.
query = new Query(report.query());

//passing the value - HERE IS THE ERROR

query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);

}

The errors says that the QueryBuild Object has not been initialized, but I
have here:

class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;

}

The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below

if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();

if (!journalList) IT ALWAYS COME HERE
throw '';

What does this mean?

I know it is a lot, but any help or thought will be greatly appreciated.

Thanks a lot!

Eduardo
Axel Kühn
2010-09-14 20:19:03 UTC
Permalink
Hi Eduardo,

please take a look at this two articles in my blog.
Post and Print SalesOrders:
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C249a12dc-34c1-4dea-9abf-6e42217f4e0d.aspx&langpair=de|en

Post and Print PurchaseOrders:
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C5cb22557-acb4-41ec-9546-c65d681e3a3d.aspx&langpair=de|en

As far as i understand your question, you can use the class purchformletter
which controls the report processing (and also posting) of the purchase order.
The first article describes this a little bit more in detail but uses
salesformletter class insted of purchformletter class.

An adittion you can take a look at i.e. the form VendPackingSlipJournal.
This form provides some functions to reprint a posted purchase packing slip.
For a posted purchase order the form is VendPurchOrderJournal.

On theses forms there are some buttons for (only) printing the reports which
are calling the report with use there menuitems.

So is should be possible to "call" the menuitems with some args holding a
reference to the needed data. For an example please take a look at these
article (only in german but the provided sample code should work).

http://www.schweda.net/blog.php?bid=208

Also keep in mind, that in this article the salesformletter class is used
(SalesOrders).
So you have to use purchformletter insted of salesformletter.

Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Eduardo
Hi,
I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)
I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)
The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.
protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query
//reportName = PurchPurchaseOrder
report = new Report(reportName);
// get the Report Query def into query obj.
query = new Query(report.query());
//passing the value - HERE IS THE ERROR
query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);
}
The errors says that the QueryBuild Object has not been initialized, but I
class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;
}
The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below
if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();
if (!journalList) IT ALWAYS COME HERE
throw '';
What does this mean?
I know it is a lot, but any help or thought will be greatly appreciated.
Thanks a lot!
Eduardo
Eduardo
2010-09-15 19:20:03 UTC
Permalink
Axel,

Thanks a lot for this information. I really like the way you explain it in
your blog. I will give it a try.

Thank you!
Post by Axel Kühn
Hi Eduardo,
please take a look at this two articles in my blog.
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C249a12dc-34c1-4dea-9abf-6e42217f4e0d.aspx&langpair=de|en
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C5cb22557-acb4-41ec-9546-c65d681e3a3d.aspx&langpair=de|en
As far as i understand your question, you can use the class purchformletter
which controls the report processing (and also posting) of the purchase order.
The first article describes this a little bit more in detail but uses
salesformletter class insted of purchformletter class.
An adittion you can take a look at i.e. the form VendPackingSlipJournal.
This form provides some functions to reprint a posted purchase packing slip.
For a posted purchase order the form is VendPurchOrderJournal.
On theses forms there are some buttons for (only) printing the reports which
are calling the report with use there menuitems.
So is should be possible to "call" the menuitems with some args holding a
reference to the needed data. For an example please take a look at these
article (only in german but the provided sample code should work).
http://www.schweda.net/blog.php?bid=208
Also keep in mind, that in this article the salesformletter class is used
(SalesOrders).
So you have to use purchformletter insted of salesformletter.
Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Eduardo
Hi,
I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)
I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)
The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.
protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query
//reportName = PurchPurchaseOrder
report = new Report(reportName);
// get the Report Query def into query obj.
query = new Query(report.query());
//passing the value - HERE IS THE ERROR
query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);
}
The errors says that the QueryBuild Object has not been initialized, but I
class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;
}
The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below
if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();
if (!journalList) IT ALWAYS COME HERE
throw '';
What does this mean?
I know it is a lot, but any help or thought will be greatly appreciated.
Thanks a lot!
Eduardo
Eduardo
2010-09-15 21:24:03 UTC
Permalink
Hi Axel,

I try yuor code and everything worked well until the line:

salesFormLetter.printJournal();

The code is the following:

public void printJournal()
{
if (journalList.len() > 0) // HERE IT FAILS AND THE ERROR IS RECORD
SORTED LIST NOT INITIALIZED
{
if (printFormletter)
{
custConfirmJour.printJournal(this, journalList);

// Tpc start ->
this.TpcProcessDocument();
// Tpc end <-
}

if (salesParmupdate.proforma)
this.removeProforma();
}
}

Any Ideas?
Post by Axel Kühn
Hi Eduardo,
please take a look at this two articles in my blog.
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C249a12dc-34c1-4dea-9abf-6e42217f4e0d.aspx&langpair=de|en
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C5cb22557-acb4-41ec-9546-c65d681e3a3d.aspx&langpair=de|en
As far as i understand your question, you can use the class purchformletter
which controls the report processing (and also posting) of the purchase order.
The first article describes this a little bit more in detail but uses
salesformletter class insted of purchformletter class.
An adittion you can take a look at i.e. the form VendPackingSlipJournal.
This form provides some functions to reprint a posted purchase packing slip.
For a posted purchase order the form is VendPurchOrderJournal.
On theses forms there are some buttons for (only) printing the reports which
are calling the report with use there menuitems.
So is should be possible to "call" the menuitems with some args holding a
reference to the needed data. For an example please take a look at these
article (only in german but the provided sample code should work).
http://www.schweda.net/blog.php?bid=208
Also keep in mind, that in this article the salesformletter class is used
(SalesOrders).
So you have to use purchformletter insted of salesformletter.
Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Eduardo
Hi,
I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)
I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)
The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.
protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query
//reportName = PurchPurchaseOrder
report = new Report(reportName);
// get the Report Query def into query obj.
query = new Query(report.query());
//passing the value - HERE IS THE ERROR
query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);
}
The errors says that the QueryBuild Object has not been initialized, but I
class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;
}
The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below
if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();
if (!journalList) IT ALWAYS COME HERE
throw '';
What does this mean?
I know it is a lot, but any help or thought will be greatly appreciated.
Thanks a lot!
Eduardo
Eduardo
2010-09-15 21:40:03 UTC
Permalink
Axel,

I got it! I basically confirmed the Sales Order first, and then I run the
Job (with your code) and it worked!

I get so excited when things work!

Thanks a lot for this Axel ... you really saved me!
Post by Axel Kühn
Hi Eduardo,
please take a look at this two articles in my blog.
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C249a12dc-34c1-4dea-9abf-6e42217f4e0d.aspx&langpair=de|en
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C5cb22557-acb4-41ec-9546-c65d681e3a3d.aspx&langpair=de|en
As far as i understand your question, you can use the class purchformletter
which controls the report processing (and also posting) of the purchase order.
The first article describes this a little bit more in detail but uses
salesformletter class insted of purchformletter class.
An adittion you can take a look at i.e. the form VendPackingSlipJournal.
This form provides some functions to reprint a posted purchase packing slip.
For a posted purchase order the form is VendPurchOrderJournal.
On theses forms there are some buttons for (only) printing the reports which
are calling the report with use there menuitems.
So is should be possible to "call" the menuitems with some args holding a
reference to the needed data. For an example please take a look at these
article (only in german but the provided sample code should work).
http://www.schweda.net/blog.php?bid=208
Also keep in mind, that in this article the salesformletter class is used
(SalesOrders).
So you have to use purchformletter insted of salesformletter.
Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Eduardo
Hi,
I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)
I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)
The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.
protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query
//reportName = PurchPurchaseOrder
report = new Report(reportName);
// get the Report Query def into query obj.
query = new Query(report.query());
//passing the value - HERE IS THE ERROR
query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);
}
The errors says that the QueryBuild Object has not been initialized, but I
class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;
}
The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below
if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();
if (!journalList) IT ALWAYS COME HERE
throw '';
What does this mean?
I know it is a lot, but any help or thought will be greatly appreciated.
Thanks a lot!
Eduardo
Eduardo
2010-09-15 21:42:06 UTC
Permalink
Ah, and another thing. I applied the following hotfix to the class
SalesFormLetter_PackingSlip in Method WriteJournalLine

https://mbs2.microsoft.com/Knowledgebase/KBDisplay.aspx?scid=kb$en-us$948500&wa=wsignin1.0
Post by Axel Kühn
Hi Eduardo,
please take a look at this two articles in my blog.
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C249a12dc-34c1-4dea-9abf-6e42217f4e0d.aspx&langpair=de|en
http://translate.google.com/translate?client=tmpg&hl=en&u=http%3A%2F%2Fblog.ak-home.net%2FPermaLink%2Cguid%2C5cb22557-acb4-41ec-9546-c65d681e3a3d.aspx&langpair=de|en
As far as i understand your question, you can use the class purchformletter
which controls the report processing (and also posting) of the purchase order.
The first article describes this a little bit more in detail but uses
salesformletter class insted of purchformletter class.
An adittion you can take a look at i.e. the form VendPackingSlipJournal.
This form provides some functions to reprint a posted purchase packing slip.
For a posted purchase order the form is VendPurchOrderJournal.
On theses forms there are some buttons for (only) printing the reports which
are calling the report with use there menuitems.
So is should be possible to "call" the menuitems with some args holding a
reference to the needed data. For an example please take a look at these
article (only in german but the provided sample code should work).
http://www.schweda.net/blog.php?bid=208
Also keep in mind, that in this article the salesformletter class is used
(SalesOrders).
So you have to use purchformletter insted of salesformletter.
Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Eduardo
Hi,
I have a requirement that says I need to allow the user to print a Purchase
Order by clicking a button in an external application. Regarding this,
everything related to the communication between AX and the app is out of the
scope of this question. I just need to know if there is a way to do this by
code (Print PO)
I have afound an article online
(https://community.dynamics.com/blogs/axsantoshkumar/archive/2010/05/04/displaying-the-standard-ax-report-in-ep-pages-of-ax.aspx)
The problem is that this article only shows how to print based on a simple
report such as Cust (in reports). I have modified the code for the example
(changed the report name to PurchPurchaseOrder) and I added a parameter.
protected void initQuery()
{
;
//Change the Query by adding filters to the Report Query
//reportName = PurchPurchaseOrder
report = new Report(reportName);
// get the Report Query def into query obj.
query = new Query(report.query());
//passing the value - HERE IS THE ERROR
query.dataSourceTable(tableNum(PurchTable)).rangeField(fieldNum(PurchTable,
PurchId)).value(purchId);
}
The errors says that the QueryBuild Object has not been initialized, but I
class PurchLineDetails_PrintPurchaseOrder
{
Args reportArgs;
ReportName reportName;
ReportRun reportRun;
Report report;
PrintJobSettings printJobSettings;
Query query; HERE I INITIALIZED THE query VALUE
PurchId purchId;
}
The other problem is that when the code into the reportRun.init(), it alwats
goes into the statement !journalList as shown below
if (element.args().record())
journalList =
FormLetter::createJournalListCopy(element.args().record());
else
journalList = element.args().object();
if (!journalList) IT ALWAYS COME HERE
throw '';
What does this mean?
I know it is a lot, but any help or thought will be greatly appreciated.
Thanks a lot!
Eduardo
Loading...