@IdleProgrammer Welcome. There are a lot of moving parts with this and you will need to hold all of the files contents in Callcontext variables or a ud temp table while they are being deleted and then put them back probably as new attachments. Epicor will remove the XfileAttch and XFileRef records and move the actual file to the deleted subdirectory.
References:
/* Check if jobHead has attachment */
callContextBpmData.Character01 = string.Empty; // you should also clear this when the put back is completed.
Ice.Diagnostics.Log.WriteEntry("in check Job has attachment");
foreach (var jhRow in ds.JobHead.Where(w => w.Unchanged()))
{
foreach (var atchRow in Db.XFileAttch.Where(x => x.Company == Session.CompanyID && x.RelatedToFile == "JobHead" && x.Key1 == jhRow.JobNum))
{
if(string.IsNullOrEmpty(callContextBpmData.Character01))
{
callContextBpmData.Character01 = atchRow.XFileRefNum.ToString();
}
else
{
callContextBpmData.Character01 = callContextBpmData.Character01 + "~" + atchRow.XFileRefNum.ToString();
}
}
Ice.Diagnostics.Log.WriteEntry($"Job {jhRow.JobNum} Part {jhRow.PartNum} has these attachments {callContextBpmData.Character01}");
}