JobEntry BPM FinalOp C#

Hi, I need your help. Might be anyone has an idea what is wrong.
I have a task to set FinalOp and AutoReceive for the last operation when Released changes to true.
I use BPM method pre processing Erp.BO.JobEntry.ChangeJobHeadJobReleased. Inside a have script (replicated from trace):

var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db);
var finalo = svc.GetByID(job);
int rowCount = finalo.JobOper.Count;
//finalo.JobOper[rowCount - 1].AutoReceive = true;
finalo.JobOper[rowCount - 1].FinalOpr = true;
finalo.JobOper[rowCount - 1].RowMod = "U";
svc.ChangeJobOperAutoReceive(true, ref finalo);
svc.Update(ref finalo);

The issue that this works with original operations, but i get error if last operation is manually added:

1 Like

You will need to make a copy of the JobOper row before changing the data and then pass both to the Update. It’s explained in this post:

1 Like

Hi, sorry to resurrect this old thread. This solution actually did not work for me in 2025.2. There are some specific quirks to setting the FinalOpr field which I finally figured out after some testing.

Here is the code:

/// BEGIN SET FINALOPR
// Job is unengineered as of this line, set finalopr on given opr, and then re-engineer and release if needed

var jeTs = jobEntrySvc.GetByID(jobNum);
var joRow = jeTs.JobOper.Where(r => r.Company == company && r.JobNum == jobNum && r.AssemblySeq == assemblySeq && r.OprSeq == oprSeq).FirstOrDefault();

if(joRow != null) {
	
	// Set FinalOpr = true on this operation so that it reports the qty to jobhead
	
	joRow.FinalOpr = true;
	// Note there is no original + updated jobOper row., only original row with FinalOpr = true
	
	// Set FinalOpr seq on JobAsmbl Record
	var jaRow = jeTs.JobAsmbl.Where(r => r.Company == joRow.Company && r.JobNum == joRow.JobNum && r.AssemblySeq == joRow.AssemblySeq).FirstOrDefault();
	
	if(jaRow != null) {
		
		var drOrig = jeTs.JobAsmbl.NewRow();
		BufferCopy.Copy(jaRow, drOrig);
		jeTs.JobAsmbl.Add(drOrig);
		jaRow.FinalOpr = joRow.OprSeq;
		jaRow.RowMod = "U";
		
		jobEntrySvc.Update(ref jeTs);
	}

}
/// END SET FINALOPR

Most importantly, for some odd reason you do NOT add the updated JobOper row to the DS. You only set FinalOpr = true on the original JobOper dataRow (I suspect its because this is not actually a Db field on JobOper but just a Ds field), but then you must also make the update to the JobAsmbl row (with the usual original + updated rows method), and pass all to JobEntrySvc.Update()… Kind of odd but this is the only thing that works for me, at least in 2025.2.

Hope this helps somebody and saves time I wasted :slight_smile:

2 Likes