如何更改缓存中的项目 [英] How to change items in cache

查看:28
本文介绍了如何更改缓存中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想更改和更改我的acumatica缓存中的缓存中的值,我想知道该怎么做

Hello i want to change and alter values inside the cache of my acumatica cache i would like to know how to do it

例如,我想更改Ext 。语法上显示第一行或第二行的成本值,或者我可以检查交易记录上是否已有数据备份。

for example i want to change the Ext. Cost value pro grammatically of the first line or the second line or can i check if there is already a "Data Backup" on transaction Descr.

< img src = https://i.stack.imgur.com/QhDeN.png alt =在此处输入图片描述>

 public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
      if (Globalvar.GlobalBoolean == true)
        {
            PXCache cache = Base.Transactions.Cache;
        APTran red = new APTran();
        red.BranchID = Base.Transactions.Current.BranchID;
        red.InventoryID = 10045;
        var curyl = Convert.ToDecimal(Globalvar.Globalred);
        red.CuryLineAmt = curyl * -1;
        cache.Insert(red);

        }
        else
        {

        }

         baseMethod();
}

此代码在persist上添加新行,但如果再次保存,则添加再次在同一行上检查是否已经有一个库存ID = 10045;在缓存中

this code add a new line on persist but if it save again it add the same line agaub u wabt ti check if there is already a inventoryID =10045; in the cache

感谢您的帮助

推荐答案

您可以通过使用视图名称或缓存类型访问您的缓存实例。例如:(其中 Base是图形实例)

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

Base.Transactions.Cache

Base.Caches<APTran>().Cache

使用缓存实例可以循环缓存使用已缓存已插入已更新已删除,具体取决于要查找的记录类型。您还可以在对象上使用 GetStatus()来确定对象是否已插入,更新等。或者调用 PXSelect 会在缓存中找到结果( PXSelectReadOnly 不会)。

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
});

如前所述,您也可以只使用 PXSelect 语句以获取值。

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

一旦您有要更新值的行,就可以设置对象属性,然后调用缓存 Update(行),然后再继续前进,就可以了。如果需要插入(行)删除(行),则类似。

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);
}

这篇关于如何更改缓存中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆