Hello,
I think I’k shooting arrows in the dark, but here it goes. First let me say that the code snipit below is all I have been given access to so far.
Here’s the background. We use custom code to create and load jobs into Epicor. The code below is the part that loads the job.
My problem is that as soon as this code hits a BPM it fails (error below) The BPM is simply a test right now with nothing more than a message box and the code fails before it even gets to that. So something in the code is not liking BPM’s. Is there something special that should be included in the code that lets it process thru BPM’s? The BPM I am using is on Jobentry.update Post-Process
private void CreateJobMtl(SalesOrderDataSet sods, JobEntryImpl jebo, OrderDtlModel line, List<JobMtlModel> boms, List<UpdatedJobModel> updatedJobs = null)
{
var dtls = sods.OrderDtl.Select(String.Format("OrderLine = {0}", line.OrderLine));
if (dtls.Count() > 0)
{
var dtl = (OrderDtlRow)dtls[0];
if (dtl.CreateJob || dtl.JobWasCreated)
{
var rels = dtl.GetOrderRelRows();
foreach (var rel in rels)
{
var jobNum = String.Format("{0}-{1}-{2}", dtl.OrderNum, dtl.OrderLine, rel.OrderRelNum);
var jeds = jebo.GetByID(jobNum);
var jeds2 = jebo.GetByID(jobNum);
var job = jeds2.JobHead[0];
var bom = boms.Where(x => !x.FromStock).OrderBy(x => x.ComponentId).ToList();
log.Debug(String.Format("Creating job mtls for {0}", jobNum));
var updatedJob = updatedJobs != null ? updatedJobs.SingleOrDefault(x => x.JobNum == jobNum) : null;
var remainingMtls = updatedJob != null ? updatedJob.RemainingMtls : null;
jebo.GetNewJobMtl(jeds2, jobNum, 0);
var mtlSeq = 10;
while (remainingMtls != null && remainingMtls.Exists(x => x.MtlSeq == mtlSeq))
{
mtlSeq += 10;
}
for (var i = 0; i < bom.Count; i++)
{
var b = bom[i];
if (remainingMtls == null || !remainingMtls.Exists(x => x.PartNum == b.PartNumber.Trim() && x.Description == b.Description && x.QtyPer == (decimal)b.Quantity))
{
var jobMtlRow = jeds2.JobMtl[jeds2.JobMtl.Rows.Count - 1];
SetJobMtl(jobMtlRow, b, job, mtlSeq, dtl.OrderLine);
jeds.JobMtl.ImportRow(jobMtlRow);
//increment mtlsqq by 10
mtlSeq += 10;
//if seq is already used increment again until not used
while (remainingMtls != null && remainingMtls.Exists(x => x.MtlSeq == mtlSeq))
{
mtlSeq += 10;
}
}
}
var mtlBom = boms.Where(x => x.FromStock).OrderBy(x => x.ComponentId).ToList();
log.Debug(String.Format("Creating job mtls (Materials) for {0}", jobNum));
var jedsMtl = jebo.GetByID(jobNum);
jebo.GetNewJobMtl(jedsMtl, jobNum, 0);
for (var i = 0; i < mtlBom.Count; i++)
{
var b = mtlBom[i];
if (remainingMtls == null || !remainingMtls.Exists(x => x.PartNum == b.PartNumber.Trim()))
{
string vMsgTxt, vMsgType, opMtlIssuedAction;
bool multipleMatch, opPartChgCompleted, vSubAvailble;
var ipPartNum = b.PartNumber;
jebo.ChangeJobMtlPartNum(jedsMtl, true, ref ipPartNum, new Guid(), null, null, out vMsgTxt, out vSubAvailble, out vMsgType, out multipleMatch, out opPartChgCompleted, out opMtlIssuedAction);
jebo.ChangeJobMtlRelatedOperation(b.OperationID, jedsMtl);
var jobMtlRow = jedsMtl.JobMtl[jedsMtl.JobMtl.Rows.Count - 1];
SetJobMtlMaterial(jobMtlRow, b, job, mtlSeq);
jeds.JobMtl.ImportRow(jobMtlRow);
//increment mtlsqq by 10
mtlSeq += 10;
//if seq is already used increment again until not used
while (remainingMtls != null && remainingMtls.Exists(x => x.MtlSeq == mtlSeq))
{
mtlSeq += 10;
}
}
}
jebo.Update(jeds);
}
}
}
}