How to change items in cache

旧城冷巷雨未停 提交于 2019-12-02 12:20:12

You can access your cache instance by using a view name or cache type. Ex: (Where 'Base' is the graph instance)

Base.Transactions.Cache

or

Base.Caches<APTran>().Cache

Using the cache instance you can loop the cached values using Cached, Inserted, Updated, or Deleted depending on which type of record you are looking for. You can also use GetStatus() on an object to find out if its inserted, updated, etc. Alternatively calling PXSelect will find the results in cache (PXSelectReadOnly will not).

So you could loop your results like so:

foreach (MyDac row in Base.Caches<MyDac>().Cache.Cached)
{
    // logic
}

If you know the key values of the cache object you are looking for you can use Locate to find by key fields:

var row = (MyDac)Base.Transactions.Cache.Locate(new MyDac
{
    MyKey1 = "",
    MyKey2 = ""
    // etc... must include each key field
});

As Mentioned before you can also just use a PXSelect statement to get the values.

Once you have the row to update the values you set the object properties and then call your cache Update(row) before the base persist and you are good to go. Similar if needing to Insert(row) or Delete(row).

So in your case you might end up with something like this in your persist:

foreach (APTran row in Base.Transactions.Cache.Cached)
{
    if (Globalvar.GlobalBoolean != true || row.TranDesc == null || !row.TranDesc.Contains("Data Backup"))
    {
        continue;
    }

    //Found my row
    var curyl = Convert.ToDecimal(Globalvar.Globalred);
    row.CuryLineAmt = curyl * -1;
    Base.Transactions.Update(row);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!