Updating DAC Extension

1.6k views Asked by At

I am trying to update some custom fields in a DAC extension via code, it is not saving the changes to the DB. The code works fine to retrieve the extension and data. What am I missing - do i have to somehow update the myLS with the extension (i thought it did that automatically)?

myLS = LineItemSerial.Select(); 
INItemLotSerialExt myext = myLS.GetExtension<INItemLotSerialExt>();

myext.UsrFrame1 = "xyz"; 
myext.UsrFrame2 = "zzz"; 
myext.UsrFrame3 = "yyy"; 

LineItemSerial.Update(myLS);
graph.Actions.PressSave();
3

There are 3 answers

0
Sin On
INItemLotSerialExt myext = LineItemSerial.GetExtension<INItemLotSerialExt>(myLS); //if LineItemSerial is a view related to the DAC. I hope LineItemSerial is a public view defined in the graph as you are trying to save the changes when u press the save of graph.

OR

INItemLotSerialExt myext = PXCache<INItemLotSerial>.GetExtension<INItemLotSerialExt>(myLS);

Is'nt this the rite way to get the extension?

From documentation

GetExtension(object)

InventoryItem item = cache.Current as InventoryItem;
InventoryItemExtension itemExt = 
    cache.GetExtension<InventoryItemExtension>(item);

OR

GetExtension(Table)

The code below gets an extension data record corresponding to the given instance of the base data record.

InventoryItem item = cache.Current as InventoryItem;
InventoryItemExtension itemExt =
    PXCache<InventoryItem>.GetExtension<InventoryItemExtension>(item);
0
Yuriy Zaletskyy On

You should say to cache of Acumatica that you want to update value:

                LineItemSerial.Cache.SetValueExt(myLS , "UsrFrame1", "xyz");
                LineItemSerial.Cache.SetValueExt(myLS , "UsrFrame2 ", "zzz");
                LineItemSerial.Cache.SetStatus(myLS , PXEntryStatus.Modified);
                LineItemSerial.Cache.Update(myLS);
                LineItemSerial.Cache.IsDirty = true;

NB. LineItemSerial.Cache.IsDirty = true; for some cases can be omitted but in my experience it was often helpful.

0
Chris H On

Try something like this...

    ContractExtension cExt = PXCache<PMProject>.GetExtension<ContractExtension>(project);    
    ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
    graph.Document.Current = graph.Document.Search<ARInvoice.projectID, ARInvoice.docDate>(projectID.Value, invoiceDate.Value);
    if(graph.Document.Current !=null)
    {
          ARInvoice i = graph.Document.Current;
          i.InvoiceNbr = cExt.CustomerPO;
          graph.Document.Update(i); 
          graph.Actions.PressSave();
     }