Skip to main content
Solved

NoteID null error when saving kit

  • January 15, 2025
  • 3 replies
  • 59 views

Forum|alt.badge.img

Hello!

I hope someone could help me with this issue:

I’m working on a solution that creates a kit specification. I haven’t done any extensions for the kit specification DAC or Graph, I’m working with an stock 24R1 instance. However, when I save the record, I get this error:

Cannot insert the value NULL into column 'NoteID', table '24R1.dbo.INKitSpecHdr'; column does not allow nulls. INSERT fails. The statement has been terminated.

I haven’t came across this issue before… Usually, when I save a record I don’t have to care about genereting the noteID. Specially if its not a customized DAC and graph.

Is there something I’m Missing?

 private static void ACUCreateKit(INKitSpecMaint kitGraph, USRMXCBOMSProduct productToSync)
        {
            kitGraph.Clear();
            INKitSpecHdr kitSpec = new INKitSpecHdr();
            kitSpec.KitInventoryID = productToSync.InventoryID;
            kitSpec.RevisionID = "WEB";
            kitSpec.Descr = productToSync.MPlaceName + " - " + productToSync.MPlaceType;
            kitSpec.IsActive = true;
            kitSpec.AllowCompAddition = false;
            kitGraph.Hdr.Insert(kitSpec);


            List<string> kitDetails = productToSync.GroupedProducts.Split(',').ToList();
            int added = 0;
            int inMP = kitDetails.Count();
            foreach (string detail in kitDetails)
            {
                List<USRMXCBOMSProduct> componentList = SelectFrom<USRMXCBOMSProduct>
                    .Where<USRMXCBOMSProduct.mPlaceProductID.IsEqual<@P.AsString>
                    .And<USRMXCBOMSProduct.active.IsEqual<@P.AsBool>>>.View.Select(kitGraph, detail.Trim(), true).RowCast<USRMXCBOMSProduct>().ToList();
                if (componentList.Count() == 1)
                {
                    USRMXCBOMSProduct component = componentList.FirstOrDefault();
                    InventoryItem itemType = InventoryItem.PK.Find(kitGraph, component.InventoryID);
                    if (itemType.StkItem.Value)
                    {
                        INKitSpecStkDet kitDetStk = new INKitSpecStkDet();
                        kitDetStk.CompInventoryID = component.InventoryID;
                        kitDetStk.DfltCompQty = 1;
                        kitGraph.StockDet.Insert(kitDetStk);
                    }
                    else
                    {
                        INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet();
                        kitDetNStk.CompInventoryID = component.InventoryID;
                        kitDetNStk.DfltCompQty = 1;
                    }
                    added++;
                }
            }


            if (added == inMP)
            {
                kitGraph.Hdr.Update(kitSpec);
                kitGraph.Actions.PressSave();
            }

Thanks for your comments in advance.

Best answer by kalima60

The NoteID error you're encountering likely stems from how the records are being inserted. Even in a stock 24R1 instance, there are some best practices to follow when working with Acumatica's data access layer. Here are the key modifications needed:

  1. When inserting the header record, use the proper graph view pattern:

kitSpec = kitGraph.Hdr.Current = kitGraph.Hdr.Insert(kitSpec);


Instead of just:

kitGraph.Hdr.Insert(kitSpec);

  1. I notice in your code that for non-stock details, you're creating the object but not actually inserting it into the graph:

INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet(); kitDetNStk.CompInventoryID = component.InventoryID; kitDetNStk.DfltCompQty = 1; // Missing the insert!


Should be:

INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet(); kitDetNStk.CompInventoryID = component.InventoryID; kitDetNStk.DfltCompQty = 1; kitGraph.NonStockDet.Insert(kitDetNStk);

  1. At the end, you can simplify the save operation:

if (added == inMP) { kitGraph.Actions.PressSave.Press(); }

The NoteID is normally handled automatically by Acumatica's PXCache when you properly use the graph's views for data manipulation. The error suggests that the cache isn't getting a chance to generate the NoteID before the insert operation hits the database.

Try these modifications and let us know if you're still experiencing issues. If you are, it might be worth checking:

  • Any database triggers or constraints that might be interfering
  • If the database schema matches the expected 24R1 version
  • Any customizations in other areas that might be affecting the Kit Specification screens

Would you share which modification resolved the issue once you've had a chance to try them?

View original
Did this topic help you find an answer to your question?

3 replies

darylbowman
Captain II
Forum|alt.badge.img+13
albertobello83 wrote:

 


    //...
    if (itemType.StkItem.Value)
    {
        INKitSpecStkDet kitDetStk = new INKitSpecStkDet();
        kitDetStk.CompInventoryID = component.InventoryID;
        kitDetStk.DfltCompQty = 1;
        kitGraph.StockDet.Insert(kitDetStk);
    }
    else
    {
        INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet();
        kitDetNStk.CompInventoryID = component.InventoryID;
        kitDetNStk.DfltCompQty = 1;
        // Insert non-stock comp
    }
    //...

 

Not sure this has anything to do with your error, but I believe you missed the code to insert the non-stock components.

You could try performing the insert of a brand new item and then updating it after the fact:

INKitSpecHdr kitSpec = kitGraph.Hdr.Insert();
kitSpec.KitInventoryID = productToSync.InventoryID;
kitSpec.RevisionID = "WEB";
kitSpec.Descr = productToSync.MPlaceName + " - " + productToSync.MPlaceType;
kitSpec.IsActive = true;
kitSpec.AllowCompAddition = false;
kitSpec = kitGraph.Hdr.Update(kitSpec);

 


kalima60
Freshman II
  • Freshman II
  • 1 reply
  • Answer
  • January 15, 2025

The NoteID error you're encountering likely stems from how the records are being inserted. Even in a stock 24R1 instance, there are some best practices to follow when working with Acumatica's data access layer. Here are the key modifications needed:

  1. When inserting the header record, use the proper graph view pattern:

kitSpec = kitGraph.Hdr.Current = kitGraph.Hdr.Insert(kitSpec);


Instead of just:

kitGraph.Hdr.Insert(kitSpec);

  1. I notice in your code that for non-stock details, you're creating the object but not actually inserting it into the graph:

INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet(); kitDetNStk.CompInventoryID = component.InventoryID; kitDetNStk.DfltCompQty = 1; // Missing the insert!


Should be:

INKitSpecNonStkDet kitDetNStk = new INKitSpecNonStkDet(); kitDetNStk.CompInventoryID = component.InventoryID; kitDetNStk.DfltCompQty = 1; kitGraph.NonStockDet.Insert(kitDetNStk);

  1. At the end, you can simplify the save operation:

if (added == inMP) { kitGraph.Actions.PressSave.Press(); }

The NoteID is normally handled automatically by Acumatica's PXCache when you properly use the graph's views for data manipulation. The error suggests that the cache isn't getting a chance to generate the NoteID before the insert operation hits the database.

Try these modifications and let us know if you're still experiencing issues. If you are, it might be worth checking:

  • Any database triggers or constraints that might be interfering
  • If the database schema matches the expected 24R1 version
  • Any customizations in other areas that might be affecting the Kit Specification screens

Would you share which modification resolved the issue once you've had a chance to try them?


Forum|alt.badge.img
  • Author
  • Freshman I
  • 13 replies
  • January 15, 2025

@kalima60 and ​@darylbowman 

Thanks both of you for pointing out the missing code. The proper graph view pattern that  ​@kalima60suggested worked perfectly.

Thank you so much!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings