This is my first complex BPM of this nature and am finding that I need a little help.
I started with a pre-processing method directive on the JobEntry.GetDetails method. Then used conditions to check if the job is related to a SO (if yes continue, else end) and if it already has a Ship Op (if yes end, else add row).
If it doesn’t have a ship op I would then like to add an operation. (I think this might be where I then want to switch to a post-processing BPM?, not certain.)
Not sure exactly that I understand what you’re trying to do but in theory, when a job is linked to a SO, it should show in the table JobProd (Field OrderNum)
I did something similar so I have a Data Directive In Transaction on JobProd. Then, if a line was added and the OrderNum is not null, I add it to the job. Here is an example of the portion to add the operation:
//Don't forget to add the Using Ice.Assemblies and reference the correct contract (JobEntry)
string message = "";
var jobEntry = ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db);
Erp.Tablesets.JobEntryTableset ds = new Erp.Tablesets.JobEntryTableset();
jobEntry.GetNewJobOper(ref ds, row.JobNum, 0);
ds.JobOper[0].StdFormat = "(StdFormat)";
jobEntry.ChangeJobOperOpCode("(OpCode)", out message, ref ds);
jobEntry.Update(ref ds);
Our situation is that we sell large assemblies that have ship ops as the last operation so they can be crated and labor taken. Then we also sell spare parts, which have methods that don’t have ship ops so they can go both to the next level job and to a sales order.
I would like to find the jobs for spare parts that are shipping from the job and add an operation for shipping at the end of it via a BPM.
@awissmann Depending on your version you may need to use Post Processing on GetDetailsMsgWarning. I had to move some routines there when we moved to 11.2. I had something close so I cobbled them together in this and it should be close to what you need.
/* to add or not to add ship op */
var jobBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db);
string Msg = string.Empty;
string errMsg = string.Empty;
bool direct = false;
Ice.Diagnostics.Log.WriteEntry("start add ship op ");
foreach (var ttJobHeadRow in result.JobHead.Where( j => j.JobNum == currJobNum ))
{
Ice.Diagnostics.Log.WriteEntry($" job is {ttJobHeadRow.JobNum} ");
// any prod link make to order
direct = Db.JobProd.With(LockHint.NoLock).Any(a => a.OrderNum != 0);
if(direct == true)
{
var LastProductionStep = Db.JobOper.With(LockHint.NoLock)
.Where(w => w.Company == Session.CompanyID && w.JobNum == ttJobHeadRow.JobNum)
.OrderByDescending(o => o.OprSeq)
.Select(s => s.OprSeq).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry($" last op is {LastProductionStep} ");
var ds = new Erp.Tablesets.JobEntryTableset();
ds = jobBO.GetByID(ttJobHeadRow.JobNum);
jobBO.GetNewJobOper(ref ds,ttJobHeadRow.JobNum,0);
var newOperRow = ds.JobOper.Where(w=>w.RowMod.ToUpper() == "A").FirstOrDefault();
if(newOperRow != null)
{
using (System.Transactions.TransactionScope txScope = IceDataContext.CreateDefaultTransactionScope())//start the transaction
{
try
{//is seq 0 or actual seq?
jobBO.ChangeJobOperOpCode("OPACK1",out Msg, ref ds);
newOperRow.LaborEntryMethod = "T";
jobBO.ChangeJobOperLaborEntryMethod("T",ref ds);
newOperRow.StdFormat = "MP";
var opTime = 10;
newOperRow.ProdStandard = (opTime * 60) / newOperRow.RunQty;;
jobBO.ChangeJobOperStdFormat(ref ds);
newOperRow.OprSeq = (int)LastProductionStep + 10;
jobBO.Update(ref ds);
Ice.Diagnostics.Log.WriteEntry($" Adding {newOperRow.OprSeq} ");
}
catch(Exception e)
{
errMsg = $"Failed to Add: {e.Message}";
}
txScope.Complete();//commit the transaction
}
}
}
var res = jobBO.GetByID(currJobNum);
resultHolder.Attach(res);
}
Ice.Diagnostics.Log.WriteEntry("exit add ship op ");
Next step that I am trying to implement would be unchecking the FinalOpr and AutoReceive buttons for the now not last operation and moving them to the last operation.
The difficulty with this is that those are not stored in the Job table but in the part rev tables. Hmmm
I couldn’t find them on the JobOpr table, but they do both seem to be on the JobAssembly table!
Thanks for the push in the right direction, I was going off of this thread. I will make sure to post this there as well incase someone else comes across it.