I am creating a tool that allows "User A" to enter the known information about an material for it to be setup and then "User B" to massage that data into approved standards before loading in as a valid part. In this tool, I have to call upon multiple graphs to create various auxiliary data points. All of these work, until I reached Kit Specifications.
The format of my various calls to each graph for processing is:
INItemSiteMaint siteGraph = PXGraph.CreateInstance<INItemSiteMaint>();
INItemSite iNItemSite = new INItemSite();
iNItemSite.InventoryID = item.InventoryID;
iNItemSite.SiteID = newItem.SiteID;
...
siteGraph.itemsitesettings.Insert(iNItemSite);
siteGraph.Actions.PressSave();
For the INKitSpecMaint graph, I can find an existing kit via PXSelect, but Search does not find a record...
Works:
INKitSpecMaint kitGraph = PXGraph.CreateInstance<INKitSpecMaint>();
kitGraph.Hdr.Current = PXSelect<INKitSpecHdr, Where<INKitSpecHdr.kitInventoryID, Equal<Required<INKitSpecHdr.kitInventoryID>>>,
OrderBy<Desc<SSINSetup.createdDateTime>>>
.SelectSingleBound(this, null, asset.AssetID);
Does not work (returns null when the above returns a kit):
iNKitSpecHdr = kitGraph.Hdr.Search<INKitSpecHdr.kitInventoryID>(asset.AssetID);
Using this methodology to create the records:
iNKitSpecHdr = new INKitSpecHdr();
iNKitSpecHdr = kitGraph.Hdr.Insert(iNKitSpecHdr);
iNKitSpecHdr.KitInventoryID = asset.AssetID;
iNKitSpecHdr.RevisionID = setup.DefaultKitRevisionID;
iNKitSpecHdr.IsActive = true;
iNKitSpecHdr = kitGraph.Hdr.Update(iNKitSpecHdr);
INKitSpecStkDet kitDetail = new INKitSpecStkDet();
kitDetail = kitGraph.StockDet.Insert(kitDetail);
kitDetail.KitInventoryID = iNKitSpecHdr.KitInventoryID;
kitDetail.RevisionID = iNKitSpecHdr.RevisionID;
kitDetail.CompInventoryID = item.InventoryID;
kitDetail.CompSubItemID = item.DefaultSubItemID;
kitDetail.AllowSubstitution = asset.AllowSubstitution;
kitDetail.DfltCompQty = asset.CompQty;
kitDetail.UOM = newItem.BaseUnit;
kitDetail = kitGraph.StockDet.Update(kitDetail);
I am wrapping the creation with a foreach to cycle through my list of kits to add the "new item" to, so the high level view is...
INKitSpecMaint kitGraph = PXGraph.CreateInstance<INKitSpecMaint>();
foreach (MyAsset asset in assets)
{
//Check if the Kit exists and create it if necessary
...
//Add the new item to the Kit (item was just created, so cannot possibly exist in the kit)
}
kitGraph.Actions.PressSave();
But when I use Actions.PressSave(), I get an error that a Non-Stock Kit may have only one revision. I only add a kit/revision when the kit does not exist at all. I have tried various variations including initializing the graph and saving it all within the foreach loop (poor performance) and clearing the graph at the top of the foreach with a multiple saves throughout, just to see if anything would work.
I'm confused how Search is not working on the main view of the graph when it is defined with an optional parameter, and I'm also confused why Acumatica would think I am adding a 2nd revision to the kit when the kit is being created.