2
votes

I have a customization that uses BLC code to obtain the results of a Generic Inquiry and use that data to run a process.

The generic inquiry has several fields that are formulae and, for some reason, the returned results show null when they do, in fact, contain an amount - calculated by the formula:

Here's the BLC code to loop through the GI rows:

GIDesign gi = PXSelectReadonly<GIDesign, Where<GIDesign.name, Equal<Required<GIDesign.name>>>>.Select(this.Base, "ACAllocationBranches");

if (gi != null)
{
    //Creates Generic Inquiry Graph for the specified inquiry
    PXGenericInqGrph graph = PXGenericInqGrph.CreateInstance(gi.DesignID.Value);

    //Set the filter...
    graph.Caches[typeof(GenericFilter)].SetValueExt(graph.Filter.Current, "RefNbr", apinv.RefNbr);

    //Loops through each returned result row of Generic Inquiry
    foreach (GenericResult resultRow in graph.Views["Results"].SelectMulti())
    {

        GIMap.Clear();
        //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[] { gi.DesignID.Value, key }))
            {
                //retrieves field value from data object specified
                var result = graph.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], resultMap.Field);

                //Load up the GIMap dictionary...
                if(resultMap.IsActive == true)
                    GIMap.Add(key + "." + resultMap.Field, result);
            }
        }
    }
}

Here's what the GI formula field looks like:

enter image description here

Unfortunately, these formula fields, like I mentioned, return null as a value in the Code, where the actual Generic Inquiry has numeric values.

Is it possible - or is there another way, through that BLC code example, to obtain those formula values?

Thanks much...

1
have you checked my answer? - Yuriy Zaletskyy

1 Answers

0
votes

I suggest you to try this code:

    public PXAction<SOOrder> Prc;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Prc")]
    protected virtual IEnumerable prc(PXAdapter adapter)
    {
        GIDesign gi =
            PXSelectReadonly<GIDesign, Where<GIDesign.name, Equal<Required<GIDesign.name>>>>.Select(this.Base,
                "PMBudget");

        var graph = PXGenericInqGrph.CreateInstance(gi.DesignID.Value);

        List<bool> descs = new List<bool>(PXView.Descendings);
        List<string> sorts = new List<string>(PXView.SortColumns);
        int startRow = 0;
        int totalRows = 0;

        var result = graph.Results.View.Select(null, null, PXView.Searches, sorts.ToArray(), descs.ToArray(),
                null, ref startRow, PXView.MaximumRows, ref totalRows)
            .Select(x => (GenericResult)x);

        return adapter.Get();
    }

Results were like those:

enter image description here

enter image description here