How to set some value in Acumatica screen and tell about it to Acumatica

Hello everybody,

today I want to write a short note about persisting something to Acumatica.

Sometime it happens that in your code you have something like this:

SomeDacInstance.Field = somevalue;

and following workflow:

User clicks on save, you code is executed, you go in record, refresh page and surprise: somevalue is not there. How to deal with it? In such cases you'll need to use method SetValueExt.

For example one of readers of mine blog had the following code:

row.LotSerialNbr = modificado2;
cache.Insert(row.LotSerialNbr)
but that approach didn't save value for two reasons:
1. simple assign of value doesn't tell acumatica cache about any changes.
2. Inserting something in the cache marks that something was changed, but that particular code will add new one record, and not modify existing one.
but following code should work:
Base.lsselect.SetValueExt<POReceiptLine.lotSerialNbr>(Base.lsselect.Current, modificado2 );

4 Comments

  • Dmitrey Makarov-Paton said

    Hi Yuri, great post. Did not work for me though? If you check the status of your entity in the cache, do you expect "Updated" after the SetValueExt call? How does differ from the following options? Do you see any probs?

    1. Insert & change the sataus, if the instance is not in the cache
    var entity = DataView.Insert(new ParkingLot( ID = 1, NbrOfSpaces = 123 ));
    DataView.Cache.SetStatus(entity, PXEntryStatus.Updated);

    2. Update item's status, if it's in the cache already
    entity.NbrOfSpaces = 123;
    DataView.Update(entity);

    3. Update Cache via SetStatus() in one go. Should add to the cache if not present
    var entity = new ParkingLot() { ID = 1, NbrOfSpaces = 123 };
    DataView.Cache.SetStatus(entity, PXEntryStatus);


    PS.
    Should it be cache.Insert(row) just above "but that approach didn't save"?

  • docotor said

    After SetValueExt I expect to see updated status.
    If to speak about details:
    1. I suppose it's status should be Inserted, not updated. With your code you cause contradiction in Acumatica cache. It tries to find something in db for updated, but in reality it should be Inserted into db. That will cause unpredictable behaviour.
    2. Second option should be updated status.
    3. For the third what status you want to achieve?

  • Dmitrey Makarov-Paton said

    Thanks for the reply. All the above achieve exactly the same result, at least that's was my intent. That is to change the status of the row object so orm can figure out that an update statement is required. No database queried in any of the options above.

    As for PXCache.SetValueExt I have not seen any changes in the status. Please check your code. Perhaps you have a consequent DataView.Update call somewhere? So, far I've used SetValueExt exclusively to trigger FieldUpdating, OnFieldVerifying, OnFieldUpdated events as per documentation.

  • Dmitrey Makarov-Paton said

    PS. Sorry, me again. :) Subject of the post is "How to set some value in Acumatica screen and tell about it to Acumatica" Not how to change the record for db update.
    Please ignore my blubbering.
    Awesome work, please keep posting.

Add a Comment