Hello Brett, I believe it is Security issues but I don’t know where to start with those, I’ve started a new Post to keep this one clean
Hello @bmanners ,
I’ve implemented this on a few modules and have just got around to doing it on the PO Entry…
In your code you have a condition to check if it is approved or not, I have the need to be able to print out unapproved POs but when I exclude the condition to check the approval status, the system fires off its own exception message saying the quote has to be approved, do you or anyone else know if this setting can be overridden, I’ve hunted through the company settings and site setting but nothing jumps out
(it also does the exception when I try to print from the Action menu)
Regards Lawson
10.2.400.13
Lawson,
I assume you are talking about POs but you mentioned Quotes as well. In our system you cant print PO’s unless it is approved (the option is disabled). Not sure if you can get around that…If you really had to print unapproved PO’s (is that a bad idea…) then you could programmatically approve it, print, then unapprove it.
Brett
Yes sorry I was meaning POs, I’ll tell them its not possible, if I down the path of programming the approvals it will cause more issues, some of our users have buyer limits and it would send off approval requests etc…
So I have been trying to get this to work for PO’s and I can’t seem to get past the list of errors. I am seeing the same Webforms and report errors that Lawson was seeing…I also can’t seem to find the second dll on my system (Microsoft.ReportViewer.WebForms.dll) which I assume is causing some of my problems. Lawson, would you be able to paste your final code that you used to get it to work? i am sure I am missing something basic but this would be a great custom to add for our purchasing team…
Thanks in advance for any help!
Hello @adamk
You need to get hold of this dll “Microsoft.ReportViewer.WebForms.dll” and put it in the Epicor client folder and reference it, make sure you do a right-click on it and unblock it in file properties
Check out this site for a copy
also, final code for the SOA
Really appreciate this @LBARKER!! Hoping to have time today to work through this today, wish me luck!
So I seem to be running into issues in two spots:
MsgInspector.Activate(); <— this gives me a compile error saying that it is abigious and needs to be a defined method
If I comment that out, I can compile but I get an error when running, seems to get stuck here:
GenerateReportPDF(“http://EXCO-ERP10-SQL.excoeng.com/ReportServer/ReportExecution2005.asmx”,reportStyle,tableguid,FileName);
Seems that one of the values is coming in blank but the system is expecting a txt/xml file?
Can you please share your code as it is now…
So this is what I have right now that is producing the following compile errors
Error: CS0103 - line 505 (2511) - The name ‘edvAutoAttachPOHeader’ does not exist in the current context
Warning: CS0467 - line 518 (2524) - Ambiguity between method ‘Microsoft.Office.Interop.Outlook._Inspector.Activate()’ and non-method ‘Microsoft.Office.Interop.Outlook.InspectorEvents_10_Event.Activate’. Using method group
extern alias Erp_Adapters_PO;
extern alias Erp_Adapters_PartRevSearch;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_VendorPPSearch;
extern alias Erp_Contracts_BO_VendCntSearch;
extern alias Erp_Contracts_BO_PO;
extern alias Erp_Contracts_BO_MiscShip;
extern alias Erp_Contracts_BO_Receipt;
extern alias Erp_Contracts_BO_JobEntry;
extern alias Erp_Contracts_BO_JobMtlSearch;
extern alias Erp_Contracts_BO_PartRevSearch;
extern alias Erp_Contracts_BO_Plant;
extern alias Ice_Contracts_BO_ReportMonitor;
extern alias Erp_Contracts_Rpt_POForm;
extern alias Erp_Adapters_UserFile;
extern alias Ice_Contracts_BO_UserFile;
extern alias Microsoft_ReportViewer_WebForms;
extern alias Microsoft_Office_Interop_Outlook;
extern alias Microsoft_ReportViewer_WinForms;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Erp.BO;
using Ice.BO;
using Ice.Lib.Broadcast;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using Ice.Core;
using Ice.Lib.Report;
using Ice.Contracts;
using System.IO;
using Epicor.ServiceModel;
using Epicor.ServiceModel.Channels;
using System.Diagnostics;
using Ice.Lib.Broadcast;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution;
using System.Windows.Forms;
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;
string Requestor;
string Supplier;
string CurrentCompany;
// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("There is no data present to email");
return;
}
// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
Requestor = (string)edvPOHeader.dataView[edvPOHeader.Row]["BuyerID"];
Supplier = (string)edvPOHeader.dataView[edvPOHeader.Row]["VendorVendorID"];
CurrentCompany = (string)edvPOHeader.dataView[edvPOHeader.Row]["Company"];
if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;
PPemailAddress = txtEmail.Text; //Supplier email address is in this Textbox.
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}
Erp.Proxy.Rpt.POFormImpl Form = WCFServiceSupport.CreateImpl<Erp.Proxy.Rpt.POFormImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Erp.Contracts.POFormSvcContract>.UriPath);
// Make the report from the PO data
Erp.Rpt.POFormDataSet POFormDS;
POFormDS = Form.GetNewParameters();
// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
switch (CurrentCompany)
{
case "A":
POFormDS.POFormParam[0].ReportStyleNum = 3001;
break;
case "B":
POFormDS.POFormParam[0].ReportStyleNum = 3002;
break;
default:
POFormDS.POFormParam[0].ReportStyleNum = 3003;
break;
}
Guid workstationid = Guid.NewGuid(); // Put a GUID in the workstationId to allow searching for the report later.
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",workstationid); // Using a GUID as the WorkstationID so it is easy to reteive this report
POFormDS.POFormParam[0].DateFormat = "dd/MM/yy";
POFormDS.POFormParam[0].ArchiveCode = 1;
POFormDS.POFormParam[0].AutoAction = "SSRSGenerate";
MessageBox.Show("Submit to System Agent ...");
Form.SubmitToAgent(POFormDS, "SystemTaskAgent", 0, 0, "Erp.UIRtp.POForm"); //Submit the report to be generate by the system agent.
// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the SSRS report.
Ice.Proxy.BO.ReportMonitorImpl RM = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.ReportMonitorImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.ReportMonitorSvcContract>.UriPath);
int timer=0;
bool morepages;
SysRptLstListDataSet RptList;
RptList = RM.GetList(@"WorkStationID ='"+workstationid+"'", 0, 0, out morepages);
while (RptList.SysRptLstList.Count == 0 ) // setup a loop to look for when the report has been generated.
{
System.Threading.Thread.Sleep(500);
timer = timer + 1;
if (timer > 120)
{
MessageBox.Show("Attempts to generate a PO pdf has timed-out. Please try again, and if that does not work, contact ERP Support");
return;
}
RptList = RM.GetList(@"WorkStationID ='"+workstationid+"'", 0, 0, out morepages);
}
string tableguid;
tableguid = RptList.SysRptLstList[0].FileName.Replace("REPORT DATABASE: ","");
// make a pdf of the PO from the report
string FileName = String.Format(@"C:\Epicor\ERP10.2Client\ExcoClient\PrintReports\{0}.pdf", PONUM);
string reportStyle;
switch (CurrentCompany)
{
case "A":
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_5.27.21";
break;
case "B":
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_5.27.21";
break;
default:
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_9-22-20";
break;
}
GenerateReportPDF("xxxx/ReportServer/ReportExecution2005.asmx",reportStyle,tableguid,FileName);
MessageBox.Show("Print Job Has been submitted - This will take approx. 10 seconds.");
// create email message
try
{
//MessageBox.Show("Attaching to email...");
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = PONUM.ToString() + " Purchase Order" ;
switch (CurrentCompany)
{
case "A":
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
case "B":
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
default:
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
}
// Set up the recipients for the email
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();
// Find the requestors email and add that
if (Requestor != "")
{
Ice.Proxy.BO.UserFileImpl userBO = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.UserFileImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.UserFileSvcContract>.UriPath);
try
{
UserFileDataSet user = userBO.GetByID(Requestor);
oRecip = oRecips.Add(user.UserFile[0].EMailAddress);
oRecip.Resolve();
}
catch
{
MessageBox.Show("Could not add requestors email address to email, user " + Requestor + " not found in Epicor.");
}
}
// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(@"\\<SERVER>\Shared\Purchasing\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
var FolderId = Guid.NewGuid().ToString("N").ToUpper();
var TempPath = Path.Combine(Path.GetTempPath(), FolderId);
if (!Directory.Exists(TempPath))
{
Directory.CreateDirectory(TempPath);
}
foreach (DataRowView row in edvAutoAttachPOHeader.dataView)
{
var AttachPath = row["FileName"].ToString();
var AttachFileName = Path.GetFileName(AttachPath);
var AttachNewPath = Path.Combine(TempPath, AttachFileName);
var AttachDesc = row["DrawDesc"].ToString();
File.Copy(AttachPath, AttachNewPath);
if (File.Exists(AttachNewPath))
{
oMsg.Attachments.Add(AttachNewPath, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
}
}
MsgInspector.Activate(); // shows the new email message as topmost window.
//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
}
catch (Exception Ex)
{
MessageBox.Show("PO Email was attempted but failed. Please try again. If that doesn't work, please contact ERP Support");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");
}
private void GenerateReportPDF(String ServerURL, String report, String tableguid, String PDFfilename)
{
// setup report variables
string deviceInfo = null;
string extension = String.Empty;
string mimeType = String.Empty;
string encoding = String.Empty;
Warning[] warnings = null;
string[] streamIDs = null;
string historyId = null;
// Create a Report Execution object
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ReportExecutionService rsExec = new ReportExecutionService();
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Url = "http://EXCO-ERP10-SQL.excoeng.com/ReportServer";
// Load the report
rsExec.LoadReport(report, historyId);
// pass parameters
rsExec.SetExecutionParameters(
new ParameterValue[] { new ParameterValue() { Name = "TableGuid", Value = tableguid } }, null);
// get pdf of report
Byte[] results = rsExec.Render("PDF", deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
File.WriteAllBytes(PDFfilename, results);
}
}
The Error part I commented out of my working code, I think what @bmanners used it for was to attach attachments from the PO Header to the email also, if you want to use that function, you will need to create an Epi data view, otherwise, comment it out
Regarding the Warning message, the code will work with warnings, otherwise, comment out that line, it only makes the email that was created pop to the front
Hi Lawson,
Ok I figured the same (epidataview error) and I bracketed out the warning…Once I do that, it compiles as you mentioned but then I get this error when I run the event
Application Error
Exception caught in: System.Web.Services
Error Detail
============
Message: Client found response content type of '', but expected 'text/xml'.
The request failed with an empty response.
Program: System.Web.Services.dll
Method: ReadResponse
Client Stack Trace
==================
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ReportExecutionService.Invoke(String methodName, Object[] parameters)
at Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ReportExecutionService.LoadReport(String Report, String HistoryID)
at Script.GenerateReportPDF(String ServerURL, String report, String tableguid, String PDFfilename)
at Script.epiButtonC1_Click(Object sender, EventArgs args)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
at Ice.Lib.Framework.EpiButton.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
at Ice.Lib.Framework.EpiButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Which after doing some message box digging, points to this line, so I think there is something not getting passed through…
GenerateReportPDF("http://xxx.com/ReportServer/ReportExecution2005.asmx",reportStyle,tableguid,FileName);
Try changing this
to
rsExec.Url = "http://EXCO-ERP10-SQL.excoeng.com/ReportServer/ReportExecution2005.asmx"";
ok so that seems to get rid of the last error…now its saying that the path to my report item isn’t valid…
The path of the item ‘/Reports/CustomReports/PurchaseOrderForm/POForm_9-22-20’ is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash
I know that is the correct location…missing something easy I am sure…appreciate all the back and forth on this Lawson
I noticed that your working code posted is for the Sales order Acknowledgment…did you ever apply it to the PO entry form?
Yeah I do have it in PO Entry but modified to send from Epicor and not Outlook,
I can see a couple of things, the last code snippet I sent had an extra " on the end of it, try removing that
it should be like this
rsExec.Url = "http://EXCO-ERP10-SQL.excoeng.com/ReportServer/ReportExecution2005.asmx";
Also are you developing this in LIVE or a Test environment, if Test, do you have the same forms in Test as in Live
Also is the form name correct, your naming convention changes between forms (dots to dashes)
Try pasting this into a web browser
If the form name is correct it should take you to a screen like this
SQL.excoeng.com/ReportServer/ReportExecution2005.asmx?/Reports/CustomReports/PurchaseOrderForm/POForm_9-22-20](http://exco-erp10-sql.excoeng.com/ReportServer/ReportExecution2005.asmx?/Reports/CustomReports/PurchaseOrderForm/POForm_9-22-20)
If the form name is correct it should take you to a screen like this
This is not showing report viewer…gives me an error…
Its strange as well…because shortly after I clear the error, I get confirmation the PO generated and it shows in the system monitor…but if I try to preview from there it won’t even give me the option too…
Something wrong with your path…
What do you get when you follow this link
http://exco-erp10-sql.excoeng.com/ReportServer/ReportExecution2005.asmx
that pulls up some XML code in the browser…asks for the user and password before it loads…
Good, that means that part of the path is correct, what is the error you get with the previous post?