I have a working BPM that adds the Sales Order demand-link into the Job. The trigger of the BPM is when the Quote> Tasks> Details> Complete, Won and Create Order are all checked, and user clicks update in Quote Entry.
This works and the Sales Order demand link is added in Job Entry.
However, the issue we discovered recently is if the Job has any attachments they are removed when the Sales Order demand is added.
Below is the code that I am using. Please advise. Thank you.
String vJobNum = callContextBpmData.Character20;
int vOrderNum = Convert.ToInt32(callContextBpmData.Number20);
//var svc = JobEntryImpl(); //Instanciated Server Side
// Declare variable hJobEntry
//Erp.Contracts.JobEntrySvcContract svc = null;
//svc = Ice.Assemblies.ServiceRenderer.GetService(Db);
// Declare svc as Assembly for JobEntry BO service.
var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db); //Instanciated Server Side
// var svc = Erp.Contracts.BO.JobEntry; //Instanciated Server Side
// Uncheck Released and Engineered
// Get the Job DataSet using GetByID method
var dsv = svc.GetByID(vJobNum);
// Set JobRelease to false
dsv.JobHead[0].JobReleased=false;
dsv.JobHead[0].RowMod="U";
svc.ChangeJobHeadJobReleased(ref dsv);
// Set JobEngineered to false
dsv.JobHead[0].JobEngineered=false;
svc.ChangeJobHeadJobEngineered(ref dsv);
// Set discovered fields from trace accordingly.
dsv.JobHead[0].EnableJobFirm=false;
dsv.JobHead[0].EngineerAllowed=true;
dsv.JobHead[0].HeaderSensitive=true;
// Set Synchronize Req by Date With Demand Links field
dsv.JobHead[0].SyncReqBy=true;
// Update the job
svc.Update(ref dsv);
// Add Demand link from Order
// Job dataset
dsv = svc.GetByID(vJobNum);
// Add a new entry into the JobProd table using the mehtod GetNewJobProd
// Job, PartNum, OrderNum, OrderLine, OrderRelNum,WarehouseCode,TargetJobNum,TargetAssemblySeq
svc.GetNewJobProd(ref dsv,dsv.JobHead[0].JobNum, dsv.JobHead[0].PartNum,vOrderNum,1,1,null,null,0);
dsv.JobProd[0].RowMod="A";
svc.Update(ref dsv);
You are correct. However, the BPM code does not change the revision of the Part. Also we know the users are not changing the rev or deleting the attachment. I tested the BPM and for some unknown reason Epicor is removing the attachment during the update step.
While adding a demand line in job entry with one attachment, the trace shows a dataset table call JobHeadAttch that contains the attachment information. This appears to be part of the Job data set.
As you can tell from my code, I am call and GETBYID to get the Job dataset. I modified the BPM in attempt to display a few of the field in the JobHeadAttch.
This resulted in an error message:
String Desc = Convert.ToString(dsv.JobHeadAttch[0].DrawDesc);
String File = Convert.ToString(dsv.JobHeadAttch[0].FileName);
Epicor.Customization.Bpm.InfoMessage.Publish("BPM - Quote.CreateOrder - Post-Processing - rsiCopyJobTypeFromQuoteActionsToOrder " + Desc);
Epicor.Customization.Bpm.InfoMessage.Publish("BPM - Quote.CreateOrder - Post-Processing - rsiCopyJobTypeFromQuoteActionsToOrder " + File );
BPM runtime caught an unexpected exception of 'ArgumentOutOfRangeException' type.
See more info in the Inner Exception section of Exception Details.
Inner Exception
===============
Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
When I tested before coding, and adding the SO demand link manually the attachment remains visible in the Job Entry tree.
Conducted more tracing, it appears that Epicor used the GetDatasetForTree method which contains the Dataset table JobHeadAttch. I used this method instead of the GetByID method and this did not correct the problem.
I just did some additional tracing and code elimination to figure out when/where the table JobHeadAttch is no longer in the dataset. As it turns out, the steps in the current code for Releasing=False and Engineering=False, then updating the Job prior to adding the demand link into the JobProd table is causing the Table JobHeadAttch to be cleared.
I believe if you were to trace creating a job from a sales order (using the Order Job Wizard) you would see that the JobProd record is the first one created. I would not be surprised if changing the JobProd record clears the other Job tables. You might want to save a copy of the JobAttach table in a separate variable so you can add it back in at the end.
The next step is figure out the row count in the JobHeadAttch and set each row RowMod=“A”.
// Set the RowMod for each row in the JobHeadAttch to “A”
for (int i = 0; i < dsv_save.JobHeadAttch.Count; i++)
{
dsv_save.JobHeadAttch[i].RowMod = “A”;