Good morning all,
I’m in the final stages of our 6 month E10 (10.2.300.17) upgrade from E9 and generally things have gone well. Uplifting 300+ BPMs I’ve written over the past 10 years has been an interesting trip down memory lane. However I have come across a few issues with converting E9 ABL code into E10 C# code. Not so much the coding itself which I’ve finally seemed to get to grips with… (with the help of some old threads on this site) but the nature of C# compared to ABL coding (don’t talk to me about Null Exceptions!). Apologies if my coding isn’t great… its a whole new world from Progress…
My current sticking point: I am using an Epicor tool called “User Schedule Process” to run some Overnight routines on our system. One of these is our own version of the “Auto Firm Jobs” routine, which runs once a day after MRP completes.
My issue is that I’m following the process captured in the trace of the Job Entry screen when ticking the Firm checkbox and getting an error from the Update Method, which does not happen from the screen.
My code is below and I would appreciate any insights into where I might be going wrong or if anyone has come across this problem before?
NB: there is some commented out code just before the Update call. I’ve tried with and without this code and get the same results.
Erp.Contracts.JobEntrySvcContract hProc = null;
string vMessage = string.Empty;
bool vBool;
string filepath = @"\\EpicAppsvr2\EpicorData\AutoFirmJobs.log";
//email initialisation
string vFrom = string.Empty;
string vTo = string.Empty;
string vCC = string.Empty;
string vSubject = string.Empty;
string vBody = string.Empty;
if (File.Exists(filepath))
{
// If file found, delete it
File.Delete(filepath);
}
//output log file initialisation
using (FileStream fs = new FileStream(filepath, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite))
{
using (StreamWriter file = new StreamWriter(fs))
{
foreach(var JobHead_Row in (from JobHead_xRow in Db.JobHead
where JobHead_xRow.Company == Session.CompanyID &&
JobHead_xRow.JobEngineered == true
orderby JobHead_xRow.PartNum ascending
select JobHead_xRow))
{
if (JobHead_Row != null)
{
if ((JobHead_Row.JobFirm == false) && (JobHead_Row.ReqDueDate >= DateTime.Today))
{
hProc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>();
if (hProc != null)
{
var dsJob = new Erp.Tablesets.JobEntryTableset();
dsJob = hProc.GetByID(JobHead_Row.JobNum);
var newJob_Row = (from newJob_xRow in dsJob.JobHead select newJob_xRow).FirstOrDefault();
if (newJob_Row != null)
{
newJob_Row.JobFirm = true;
newJob_Row.LockQty = true;
newJob_Row.RowMod = "U";
/* hProc.CheckUnfirmJob(newJob_Row.JobNum, newJob_Row.PartNum, out vMessage);
hProc.CheckToReschedule(Session.CompanyID, newJob_Row.JobNum, newJob_Row.ReqDueDate, newJob_Row.ProdQty, newJob_Row.DueDate, newJob_Row.StartDate, true, out vMessage);
hProc.CheckForChanges(Session.CompanyID, newJob_Row.JobNum, true, false, false, false, false, false, false, false, false, out vBool); */
fileInfo = string.Format("New Firm Job: Original Job:= {0} JobNum:= {1} Part:= {2} Required:= {3:dd/MM/yy} Quantity:= {4:F2}", JobHead_Row.JobNum, newJob_Row.JobNum, newJob_Row.PartNum, newJob_Row.ReqDueDate, newJob_Row.ProdQty);
file.WriteLine(fileInfo);
// Update the dataset.
hProc.Update(ref dsJob);
}
}
hProc.Dispose();
}
}
}
}
file.Close();
}
var mailer = this.GetMailer(async: false);
var message = new Ice.Mail.SmtpMail();
vFrom = "e10system@company.com";
vTo = "user@company.com";
vCC = "system@company.com";
vSubject = "E10-OVNT: Auto-Firm Jobs Log";
vBody = "See attachment for details of the latest process run.";
message.SetFrom(vFrom);
message.SetTo(vTo);
message.SetCC(vCC);
message.SetSubject(vSubject);
message.SetBody(vBody);
if (File.Exists(filepath))
{
Dictionary<string, string> attachments = new Dictionary<string, string>();
attachments.Add("MyFirstAttachment", filepath);
mailer.Send(message, attachments);
}