Epicor 9.05 Printing Reports From .net BO

Any one know how to do this with 64bit? I get the following error:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Inner Stack Trace

=================

at Script.getSession(IntPtr pHandle)

at Script.InitializeCustomCode()

 

Good Day Group,

I am on Epicor 9.05.607a. I am working on a custom application for my company dealing with shipping and packing slips. Long story short, I would like to print a packing slip from my application. I have id the BO dealing with printing using the trace tool and the sequence of methods:

Epicor.Mfg.Rpt.PackingSlipPrint.GetNewParameters()
Epicor.Mfg.Rpt.PackingSlipPrint.GetRptArchiveList()
Epicor.Mfg.Rpt.PackingSlipPrint.PackNumDefaults()
Epicor.Mfg.Rpt.PackingSlipPrint.SubmitToAgent()

I manage to submit a task to the system agent but there is no printing. Also Epicor needs to be running in order for this to work. Has any body printed from outside Epicor using .net BO?

Thanks,
Joel
Come to our presentation at perspectives we'll discuss this :)
Its kinda complex you have to get the parameters right an the Work Station
ID rigth and Epicor has to be running at least the Agent.

*Jose C Gomez*
*Software Engineer*
*
*
*checkout my new blog <http://www.usdoingstuff.com> *
*
*T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com
<http://www.linkedin.com/in/josecgomez> <http://www.facebook.com/josegomez>
<http://www.google.com/profiles/jose.gomez> <http://www.twitter.com/joc85>
<http://www.josecgomez.com/professional-resume/>
<http://www.josecgomez.com/feed/>
<http://www.usdoingstuff.com>

*Quis custodiet ipsos custodes?*



On Fri, Mar 30, 2012 at 10:54 AM, jobando018 <eltico_018@...> wrote:

> **
>
>
> Good Day Group,
>
> I am on Epicor 9.05.607a. I am working on a custom application for my
> company dealing with shipping and packing slips. Long story short, I would
> like to print a packing slip from my application. I have id the BO dealing
> with printing using the trace tool and the sequence of methods:
>
> Epicor.Mfg.Rpt.PackingSlipPrint.GetNewParameters()
> Epicor.Mfg.Rpt.PackingSlipPrint.GetRptArchiveList()
> Epicor.Mfg.Rpt.PackingSlipPrint.PackNumDefaults()
> Epicor.Mfg.Rpt.PackingSlipPrint.SubmitToAgent()
>
> I manage to submit a task to the system agent but there is no printing.
> Also Epicor needs to be running in order for this to work. Has any body
> printed from outside Epicor using .net BO?
>
> Thanks,
> Joel
>
>
>


[Non-text portions of this message have been removed]
Never printed from outside Epicor but here is some code that I use to
print a BAQReport from a dashboard.

I have to have Epicor open for this to work.

Some of the code was remove that was specific to my use to make is
smaller.

Let me now if you have any questions.



public static class Script

{



// ** Wizard Insert Location - Do Not Remove 'Begin/End
Wizard Added Module Level Variables' Comments! **

// Begin Wizard Added Module Level Variables **



// End Wizard Added Module Level Variables **





// Add Custom Module Level Variables Here **

private static Process current = null;

private static System.IntPtr hProcess =
default(System.IntPtr);

private static int consoleSessionID = 0;



[DllImport("Epicor.Mfg.Lib.GetConsoleSessionID.dll",
CharSet = CharSet.Auto)]

public static extern int getSession(IntPtr pHandle);





public static void InitializeCustomCode()

{



// ** Wizard Insert Location - Do not
delete 'Begin/End Wizard Added Variable Initialization' lines **

// Begin Wizard Added Variable
Initialization



// End Wizard Added Variable
Initialization

// Begin Wizard Added Custom Method
Calls



btnPrintPickList.Click += new
System.EventHandler(Script.btnPrintPickList_Click);



btnClearPrint.Click += new
System.EventHandler(Script.btnClearPrint_Click);

// End Wizard Added Custom Method Calls



current = Process.GetCurrentProcess();

hProcess = current.Handle;

consoleSessionID = getSession(hProcess);

if ((consoleSessionID < 0))

{

consoleSessionID = 0;

}

}





public static void DestroyCustomCode()

{



// ** Wizard Insert Location - Do not
delete 'Begin/End Wizard Added Object Disposal' lines **

// Begin Wizard Added Object Disposal



btnPrintPickList.Click -= new
System.EventHandler(Script.btnPrintPickList_Click);

btnClearPrint.Click -= new
System.EventHandler(Script.btnClearPrint_Click);

// End Wizard Added Object Disposal

// Begin Custom Code Disposal

current = null;

// End Custom Code Disposal



}





private static void btnPrintPickList_Click(object sender,
System.EventArgs args)

{

// ** Place Event Handling Code Here **



Infragistics.Win.UltraWinGrid.SelectedRowsCollection selectedRows;

Session epiSession;

epiSession = (Session) MainController.Session;

BAQReport rptBAQReport = new
BAQReport(epiSession.ConnectionPool);



BAQReportDataSet rptDSBAQReport =
rptBAQReport.GetNewBAQReportParam("MISOPickList");



EpiUltraGrid myGrid = (EpiUltraGrid)
csm.GetNativeControlReference("07587698-1612-41ef-a85a-38b77c7be07c");



//Check to see if any rows are selected.
If not, stop.

if (myGrid.Selected.Rows.Count < 1)

{

myGrid = null;

rptDSBAQReport = null;

rptBAQReport = null;

epiSession = null;

MessageBox.Show("Please
select an order and then try again.");

return;

}



//Iterate through selected rows, build
order list and determine greatest shipby date

selectedRows = myGrid.Selected.Rows;

List<string> lstOrderNums = new List<string>();

string Filter1P1 = "<?xml version =
'1.0' encoding = 'UTF-8'?> <BAQReport> <BAQFilter>
<TableName>OrderHed</TableName> <FieldName>OrderNum</FieldName>
<Comparison>list</Comparison> <FieldValue>";

string Filter1P2 = "</FieldValue>
<RowIdent>FilterList1</RowIdent> </BAQFilter> </BAQReport>";

// Loop through all the selected rows

//

for ( int i = 0; i < selectedRows.Count; i++ )

{

Infragistics.Win.UltraWinGrid.UltraGridRow row;



row = selectedRows[i];



//add the order number
to the list if it isn't already

if
(!lstOrderNums.Contains(row.Cells["OrderHed.OrderNum"].Text))

{


lstOrderNums.Add(row.Cells["OrderHed.OrderNum"].Text);

}

}



//build order number string

StringBuilder sb = new StringBuilder();



foreach (string orderNum in
lstOrderNums)

{

if (sb.Length > 0)

{


sb.Append("~");

}



sb.Append(orderNum);

}



//Set fields accordingly

//Some of these field are set because it was observed from
tracing that these

//values changed from default dataset

//

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["BAQID"] =
"MATS-SOPickSlip";


rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["ReportTitle"] = "Sales
Order Pick List";


rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["Filter1"] = Filter1P1 +
sb.ToString() + Filter1P2;


rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["DCDUserID"] =
epiSession.UserID;


rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["BAQRptID"] =
"MISOPickList";

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["AutoAction"] =
"Preview";

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["AgentID"] =
"SystemTaskAgent";

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["WorkstationID"]
= Environment.MachineName + " " + consoleSessionID.ToString();

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["DateFormat"] =
"mm/dd/yyyy";

rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["NumericFormat"]
= ",.";



//Send Pick List to System Agent for
printing


rptBAQReport.SubmitToAgent(rptDSBAQReport, "SystemTaskAgent", 0, 0,
"Epicor.Mfg.UIRpt.BAQReport;MISOPickList");



MessageBox.Show("Pick List Print Job
Submitted.");

}

}



From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of jobando018
Sent: Friday, March 30, 2012 10:55 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Epicor 9.05 Printing Reports From .net BO





Good Day Group,

I am on Epicor 9.05.607a. I am working on a custom application for my
company dealing with shipping and packing slips. Long story short, I
would like to print a packing slip from my application. I have id the BO
dealing with printing using the trace tool and the sequence of methods:

Epicor.Mfg.Rpt.PackingSlipPrint.GetNewParameters()
Epicor.Mfg.Rpt.PackingSlipPrint.GetRptArchiveList()
Epicor.Mfg.Rpt.PackingSlipPrint.PackNumDefaults()
Epicor.Mfg.Rpt.PackingSlipPrint.SubmitToAgent()

I manage to submit a task to the system agent but there is no printing.
Also Epicor needs to be running in order for this to work. Has any body
printed from outside Epicor using .net BO?

Thanks,
Joel












Joe Rojas | Director of Information Technology | Mats Inc
dir: 781-573-0291 | cell: 781-408-9278 | fax: 781-232-5191
jrojas@... | www.matsinc.com Ask us about our clean, green and beautiful matting and flooring


This message is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.


[Non-text portions of this message have been removed]
Thank you so much, I got it to work in one build. The system agent needs to be running. This is my solution:

[DllImport(@"C:\Epicor905\Client\Epicor.Mfg.Lib.GetConsoleSessionID.dll",CharSet = CharSet.Auto)]
public static extern int getSession(IntPtr pHandle);
Process current;
System.IntPtr hProcess = default(System.IntPtr);
int consoleSessionID = 0;


//After connecting the report BO that I named PackingSlipPrintBO with a session

public void print(string packID){


//Get an empty report strong typed DataSet with the default report already set
Epicor.Mfg.Rpt.PackingSlipPrintDataSet reportDataSet =
this.PackingSlipPrintBO.GetNewParameters();
Epicor.Mfg.Rpt.PackingSlipPrintDataSet.PackingSlipParamRow parameterRowForPrintingJob = reportDataSet.PackingSlipParam[0];
//Setup Parameters
parameterRowForPrintingJob.PackNumList = packID;
parameterRowForPrintingJob.AutoAction = "Preview";
parameterRowForPrintingJob.AgentID = "SystemTaskAgent";
parameterRowForPrintingJob.WorkstationID =
Environment.MachineName + " " + consoleSessionID.ToString();
parameterRowForPrintingJob.DateFormat = "mm/dd/yyyy";
parameterRowForPrintingJob.NumericFormat = ",.";

this.PackingSlipPrintBO.SubmitToAgent(reportDataSet,
"SystemTaskAgent", 0, 0,
"Epicor.Mfg.UIRpt.PackingSlipPrint");
}

//Parameters to send to print
parameterRowForPrintingJob.AutoAction = "Print";
parameterRowForPrintingJob.PrinterName = "Printer Name";




--- In vantage@yahoogroups.com, Joe Rojas <jrojas@...> wrote:
>
> Never printed from outside Epicor but here is some code that I use to
> print a BAQReport from a dashboard.
>
> I have to have Epicor open for this to work.
>
> Some of the code was remove that was specific to my use to make is
> smaller.
>
> Let me now if you have any questions.
>
>
>
> public static class Script
>
> {
>
>
>
> // ** Wizard Insert Location - Do Not Remove 'Begin/End
> Wizard Added Module Level Variables' Comments! **
>
> // Begin Wizard Added Module Level Variables **
>
>
>
> // End Wizard Added Module Level Variables **
>
>
>
>
>
> // Add Custom Module Level Variables Here **
>
> private static Process current = null;
>
> private static System.IntPtr hProcess =
> default(System.IntPtr);
>
> private static int consoleSessionID = 0;
>
>
>
> [DllImport("Epicor.Mfg.Lib.GetConsoleSessionID.dll",
> CharSet = CharSet.Auto)]
>
> public static extern int getSession(IntPtr pHandle);
>
>
>
>
>
> public static void InitializeCustomCode()
>
> {
>
>
>
> // ** Wizard Insert Location - Do not
> delete 'Begin/End Wizard Added Variable Initialization' lines **
>
> // Begin Wizard Added Variable
> Initialization
>
>
>
> // End Wizard Added Variable
> Initialization
>
> // Begin Wizard Added Custom Method
> Calls
>
>
>
> btnPrintPickList.Click += new
> System.EventHandler(Script.btnPrintPickList_Click);
>
>
>
> btnClearPrint.Click += new
> System.EventHandler(Script.btnClearPrint_Click);
>
> // End Wizard Added Custom Method Calls
>
>
>
> current = Process.GetCurrentProcess();
>
> hProcess = current.Handle;
>
> consoleSessionID = getSession(hProcess);
>
> if ((consoleSessionID < 0))
>
> {
>
> consoleSessionID = 0;
>
> }
>
> }
>
>
>
>
>
> public static void DestroyCustomCode()
>
> {
>
>
>
> // ** Wizard Insert Location - Do not
> delete 'Begin/End Wizard Added Object Disposal' lines **
>
> // Begin Wizard Added Object Disposal
>
>
>
> btnPrintPickList.Click -= new
> System.EventHandler(Script.btnPrintPickList_Click);
>
> btnClearPrint.Click -= new
> System.EventHandler(Script.btnClearPrint_Click);
>
> // End Wizard Added Object Disposal
>
> // Begin Custom Code Disposal
>
> current = null;
>
> // End Custom Code Disposal
>
>
>
> }
>
>
>
>
>
> private static void btnPrintPickList_Click(object sender,
> System.EventArgs args)
>
> {
>
> // ** Place Event Handling Code Here **
>
>
>
> Infragistics.Win.UltraWinGrid.SelectedRowsCollection selectedRows;
>
> Session epiSession;
>
> epiSession = (Session) MainController.Session;
>
> BAQReport rptBAQReport = new
> BAQReport(epiSession.ConnectionPool);
>
>
>
> BAQReportDataSet rptDSBAQReport =
> rptBAQReport.GetNewBAQReportParam("MISOPickList");
>
>
>
> EpiUltraGrid myGrid = (EpiUltraGrid)
> csm.GetNativeControlReference("07587698-1612-41ef-a85a-38b77c7be07c");
>
>
>
> //Check to see if any rows are selected.
> If not, stop.
>
> if (myGrid.Selected.Rows.Count < 1)
>
> {
>
> myGrid = null;
>
> rptDSBAQReport = null;
>
> rptBAQReport = null;
>
> epiSession = null;
>
> MessageBox.Show("Please
> select an order and then try again.");
>
> return;
>
> }
>
>
>
> //Iterate through selected rows, build
> order list and determine greatest shipby date
>
> selectedRows = myGrid.Selected.Rows;
>
> List<string> lstOrderNums = new List<string>();
>
> string Filter1P1 = "<?xml version =
> '1.0' encoding = 'UTF-8'?> <BAQReport> <BAQFilter>
> <TableName>OrderHed</TableName> <FieldName>OrderNum</FieldName>
> <Comparison>list</Comparison> <FieldValue>";
>
> string Filter1P2 = "</FieldValue>
> <RowIdent>FilterList1</RowIdent> </BAQFilter> </BAQReport>";
>
> // Loop through all the selected rows
>
> //
>
> for ( int i = 0; i < selectedRows.Count; i++ )
>
> {
>
> Infragistics.Win.UltraWinGrid.UltraGridRow row;
>
>
>
> row = selectedRows[i];
>
>
>
> //add the order number
> to the list if it isn't already
>
> if
> (!lstOrderNums.Contains(row.Cells["OrderHed.OrderNum"].Text))
>
> {
>
>
> lstOrderNums.Add(row.Cells["OrderHed.OrderNum"].Text);
>
> }
>
> }
>
>
>
> //build order number string
>
> StringBuilder sb = new StringBuilder();
>
>
>
> foreach (string orderNum in
> lstOrderNums)
>
> {
>
> if (sb.Length > 0)
>
> {
>
>
> sb.Append("~");
>
> }
>
>
>
> sb.Append(orderNum);
>
> }
>
>
>
> //Set fields accordingly
>
> //Some of these field are set because it was observed from
> tracing that these
>
> //values changed from default dataset
>
> //
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["BAQID"] =
> "MATS-SOPickSlip";
>
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["ReportTitle"] = "Sales
> Order Pick List";
>
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["Filter1"] = Filter1P1 +
> sb.ToString() + Filter1P2;
>
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["DCDUserID"] =
> epiSession.UserID;
>
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["BAQRptID"] =
> "MISOPickList";
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["AutoAction"] =
> "Preview";
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["AgentID"] =
> "SystemTaskAgent";
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["WorkstationID"]
> = Environment.MachineName + " " + consoleSessionID.ToString();
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["DateFormat"] =
> "mm/dd/yyyy";
>
> rptDSBAQReport.Tables["BAQReportParam"].Rows[0]["NumericFormat"]
> = ",.";
>
>
>
> //Send Pick List to System Agent for
> printing
>
>
> rptBAQReport.SubmitToAgent(rptDSBAQReport, "SystemTaskAgent", 0, 0,
> "Epicor.Mfg.UIRpt.BAQReport;MISOPickList");
>
>
>
> MessageBox.Show("Pick List Print Job
> Submitted.");
>
> }
>
> }
>
>
>
> From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
> Of jobando018
> Sent: Friday, March 30, 2012 10:55 AM
> To: vantage@yahoogroups.com
> Subject: [Vantage] Epicor 9.05 Printing Reports From .net BO
>
>
>
>
>
> Good Day Group,
>
> I am on Epicor 9.05.607a. I am working on a custom application for my
> company dealing with shipping and packing slips. Long story short, I
> would like to print a packing slip from my application. I have id the BO
> dealing with printing using the trace tool and the sequence of methods:
>
> Epicor.Mfg.Rpt.PackingSlipPrint.GetNewParameters()
> Epicor.Mfg.Rpt.PackingSlipPrint.GetRptArchiveList()
> Epicor.Mfg.Rpt.PackingSlipPrint.PackNumDefaults()
> Epicor.Mfg.Rpt.PackingSlipPrint.SubmitToAgent()
>
> I manage to submit a task to the system agent but there is no printing.
> Also Epicor needs to be running in order for this to work. Has any body
> printed from outside Epicor using .net BO?
>
> Thanks,
> Joel
>
>
>
>
>
>
>
>
>
>
>
>
> Joe Rojas | Director of Information Technology | Mats Inc
> dir: 781-573-0291 | cell: 781-408-9278 | fax: 781-232-5191
> jrojas@... | www.matsinc.com Ask us about our clean, green and beautiful matting and flooring
>
>
> This message is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.
>
>
> [Non-text portions of this message have been removed]
>