I wrote a customization to add a link for any files uploaded to a SO Line item into a Production Order.
It works, but I am breaking all kinds of rules. I am not supposed to update a cache or do BQL statements in the RowSelected handler.
The goal is that each time a Production Order is opened on screen AM201500, I do a check against the SO Lines related to the Sales Order for that Production Order and create links to the “Files” on the Production Order. Each SO Line could have multiple attachments and we want those attachments available on the Production Order.
Also, there is most likely a better way to accomplish this regardless of which handler I use, but this is the only way I know to do it.
I would appreciate any inputs/critiques you might have.
protected void _(Events.RowSelected<AMProdItem> e)
{
var row = (AMProdItem)e.Row;
if (row.OrdNbr != null)
{
using (new PXConnectionScope())
{
//create a generic graph
PXGraph genericGraph = new PXGraph();
var noteDocCache = genericGraph.Cachestypeof(NoteDoc)];
//Get a listing of all SO Line items that have a file attached.
//there could be more than one file per line
foreach (UploadFile uf in SelectFrom<UploadFile>
.InnerJoin<NoteDoc>.On<NoteDoc.fileID.IsEqual<UploadFile.fileID>>
.InnerJoin<SOLine>.On<SOLine.noteID.IsEqual<NoteDoc.noteID>>
.Where<SOLine.orderNbr.IsEqual<@P.AsString>
.And<SOLine.orderType.IsEqual<@P.AsString>>>
.View.Select(Base, row.OrdNbr, row.OrdTypeRef))
{
//see if the uploaded file has already been added to the NoteDoc table for the respective noteID and fileID
NoteDoc searchNoteDoc = SelectFrom<NoteDoc>
.Where<NoteDoc.noteID.IsEqual<@P.AsGuid>
.And<NoteDoc.fileID.IsEqual<@P.AsGuid>>>
.View.Select(Base, row.NoteID, uf.FileID);
if (searchNoteDoc == null)
{
NoteDoc noteDoc = new NoteDoc()
{
NoteID = row.NoteID,
FileID = uf.FileID
};
noteDocCache.Update(noteDoc);
noteDocCache.Persist(PXDBOperation.Insert);
}
}
}
}
}
Thank you!
Joe Schmucker