从BLC /图形代码

时间:2017-10-26 14:01:45

标签: acumatica

我需要获取由BLC /图形逻辑内部的通用查询提供的数据集或结果数组。

我已经给出了以下作为示例,但这显然只会返回一个计数。

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> Test;
[PXButton]
[PXUIField]
protected void test()
{
    var dataGraph = PXGenericInqGrph.CreateInstance("GI000010");
    if (dataGraph != null)
    {
        var count = dataGraph.Views["Results"].SelectMulti().Count;
    }
}
}

当我在返回的变量中使用索引时,我没有得到任何类似于GI中实际数据行的任何内容,例如:

dataGraph.Views["Results"].SelectMulti()[0]

这不会返回实际数据。我已经尝试过dataGraph.Views [&#34; Results&#34;]对象提供的几个方法/属性,但没有一个给我我需要的结果。

是否有方法或属性只返回通用查询的实际结果的数据集或数组?

2 个答案:

答案 0 :(得分:1)

这将为您提供结果列表。每个列表元素将包含GI行结果的1行所涉及的记录(每个连接表)。只有地理标志中包含的那些字段才具有我认为的值。

public PXAction<SOOrder> Test;
[PXButton]
[PXUIField]
protected void test()
{
    // Using "Invoiced Items" (GI000008) GI in 2017R2
    var dataGraph = PXGenericInqGrph.CreateInstance("GI000008");
    if (dataGraph == null)
    {
        return;
    }

    var resultList = dataGraph.Results.Select().FirstTableItems.ToList();

    foreach (GenericResult genericResult in resultList)
    {
        //  Note: not all values are pulled into the DAC, only those used in the query
        var arInvoice = GetDac<PX.Objects.AR.ARInvoice>(genericResult);
        var arTran = GetDac<PX.Objects.AR.ARTran>(genericResult);
        var customer = GetDac<PX.Objects.AR.Customer>(genericResult);
        var customerClass = GetDac<PX.Objects.AR.Customer>(genericResult);
        var address = GetDac<PX.Objects.AR.Customer>(genericResult);
        var bAccount = GetDac<PX.Objects.CR.BAccount>(genericResult);
        var inventoryItem = GetDac<PX.Objects.IN.InventoryItem>(genericResult);

        var formulaValues = genericResult.Values.Last();
    }
}

protected virtual T GetDac<T>(GenericResult genericResult) where T : class, PX.Data.IBqlTable
{
    // Example: 
    //var customer = (PX.Objects.AR.Customer)genericResult.Values["Customer"]
    return (T)(genericResult?.Values != null && 
        genericResult.Values.ContainsKey(typeof(T).Name)
        ? genericResult.Values[typeof(T).Name]
        : null);
}

答案 1 :(得分:1)

我为非库存项目开发的以下自定义按钮将调用指定的一般查询,更新其参数值并检索所有结果行和相应的字段结果,而无需了解特定的DAC。

public class NonStockItemMaintExtension : PXGraphExtension<NonStockItemMaint>
    {
        #region Buttons
        public PXAction<InventoryItem> RunSummary;

        [PXButton]
        [PXUIField(DisplayName = "Run Summary")]
        public virtual IEnumerable runSummary(PXAdapter adapter)
        {
            InventoryItem item = Base.Item.Current;

            GIDesign design = PXSelectReadonly<GIDesign, Where<GIDesign.name, Equal<Required<GIDesign.name>>>>.Select(this.Base, "ItemTrans");
            if (design != null)
            {
                PXLongOperation.StartOperation(this.Base, delegate ()
                {
                    //Creates Generic Inquiry Graph for the specified inquiry
                    PXGenericInqGrph graph = PXGenericInqGrph.CreateInstance(design.DesignID.Value);

                    if (design != null)
                    {
                        //Sets parameter value
                        graph.Caches[typeof(GenericFilter)].SetValueExt(graph.Filter.Current, "Item", item.InventoryCD);

                        //Loops through each returned result row of Generic Inquiry
                        foreach (GenericResult resultRow in graph.Views["Results"].SelectMulti())
                        {
                            //Loops through objects returned from one - not an object per field
                            foreach (string key in resultRow.Values.Keys)
                            {
                                //Loops through list of each object and the fields we need values from for each data key
                                foreach (GIResult resultMap in PXSelectReadonly<GIResult, Where<GIResult.designID, Equal<Required<GIResult.designID>>, And<GIResult.objectName, Equal<Required<GIResult.objectName>>>>>.Select(graph, new object[] { design.DesignID.Value, key }))
                                {
                                    //retrieves field value from data object specified
                                    var result = graph.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], resultMap.Field);
                                }
                            }
                        }
                    }
                });
            }

            return adapter.Get();
        }
        #endregion
    }

一般查询中引用的表: enter image description here

要从查询中检索的数据字段:

enter image description here

正在填充的参数:

enter image description here

正在获取值:

enter image description here