0
votes

I'm adding a new DAC/Graph that will drive purchases, and I want to route through the Create Purchase Order processing screen to keep it consistent with Acumatica ERP. I am leveraging INReplenishmentMaint to create the INItemPlan record, but I need a usrField to capture my source reference number (similar to a SO Order #).

After the INItemPlan record is saved, I update the INItemPlanExt.usrField to capture my source record via:

planExt.UsrField = myData.myKeyField;
graphRepl.Caches[typeof(INItemPlanExt)].Update(planExt);
graphRepl.Caches[typeof(INItemPlanExt)].Persist(PXDBOperation.Update);

However, if I have not created the purchase order yet, I can't update myData with the PO reference. Therefore, I need to update an existing INItemPlan record if it exists when clicking my "Create PO" button in my custom graph but keep creating a new INItemPlan record instead.

My dilemma is that the connection to myData is in INItemPlanExt, which I can lookup from my INItemPlan row, but I need to lookup in reverse... that is, I need to find my INItemPlan from the value stored in my usrField on the Ext DAC.

How do I get back to the base DAC from the Ext DAC? Or am I just going about this wrong? (If so, please tell me how I should go about processing myData row(s) into a PO to be consistent with Acumatica ERP.) I'm using 2018R1.

1

1 Answers

0
votes

Pretty simple solution... I made a custom class that inherits from INItemPlan and added my field there. That allowed me to access the field when searching the INItemPlan table to find my custom reference.

[Serializable()]
public partial class ZZINItemPlan : INItemPlan, IBqlTable
{
    #region UsrTagNbr
    [PXDBString(15)]
    [PXUIField(DisplayName ="Tag Nbr.")]
    public virtual string UsrTagNbr { get; set; }
    public abstract class usrTagNbr : PX.Data.IBqlField { }
    #endregion
}

Next, find the row from "usrTagNbr"...

ZZINItemPlan plan =
    PXSelect<ZZINItemPlan, Where<ZZINItemPlan.usrTagNbr, Equal<Required<ZZINItemPlan.usrTagNbr>>>>
    .Select(this, myData.TagNbr);

If the TagNbr isn't found to apply updates, then make a new row...

if (plan == null) plan = new ZZINItemPlan();
[set values here]

Let's execute the normal graph to update (which will insert if not found) into the database so that all the normal business logic is hit for validation. (We must cast the ZZINItemPlan data to INItemPlan for the graph.)

INReplenishmentMaint graphRepl = PXGraph.CreateInstance<INReplenishmentMaint>();
INItemPlan iplan = graphRepl.Plans.Update((INItemPlan) plan);

Since the usrTagNbr field has been lost by casting to INItemPlan, we need to push the TagNbr data into the DAC Extension.

INItemPlanExt planExt = PXCache<INItemPlan>.GetExtension<INItemPlanExt>(iplan);

planExt.UsrTagNbr = ncmTag.TagNbr;
graphRepl.Caches[typeof(INItemPlanExt)].Update(planExt);
graphRepl.Caches[typeof(INItemPlanExt)].Persist(PXDBOperation.Update);