0

I've created a custom selector that has logic which depends on the value of a field in a header section of a screen. Since the logic is not in the graph which holds the views, how would I obtain the current value of the cache for this header section? I've set the field I'm referencing in the header to commitchanges=true and I've even put SyncPosition=true in the header section of the page. The following logic does not give me the current value that is (I'm assuming) in the cache:

mh = (xTACMappingHeader)PXSelect< xTACMappingHeader,
                        Where<    xTACMappingHeader.mappingName, Equal<Required<xTACMappingDetail.mappingName>>>>.Select(new PXGraph<FinancialTranslatorMaint>(), md.MappingName);

What's the best way to retrieve the current value of the cache in a graph outside of that graph?

Thanks...

pmfith
  • 831
  • 6
  • 24

2 Answers2

2

PXCache objects never exist outside of graph. You can access current graph through the _Graph field of PXCustomSelectorAttribute:

protected PXGraph _Graph;

something like:

mh = (xTACMappingHeader)PXSelect<…>.Select(_Graph, md.MappingName);

to access current value of the cache:

_Graph.Caches[typeof(YourDAC)].Current

While initializing caches, Acumatica Framework invokes CacheAttached() method on for every field attribute. PXCustomSelectorAttribute assigns value for the _Graph field based on Graph property of the currently initializing PXCache object:

public class PXCustomSelectorAttribute : PXSelectorAttribute
{
    ...

    public override void CacheAttached(PXCache sender)
    {
        ...

        _Graph = sender.Graph;

        ...
    }

    ...
}
RuslanDev
  • 6,718
  • 1
  • 14
  • 27
  • Obviously the _Graph variable is some kind of implicit part of the Custom Selector Attribute. I have no idea how it gets its value, but it seems to work as you specified. I'd still like to know just how it gets its value, but that's not so important at the moment. Thanks much – pmfith Jul 28 '16 at 16:55
2

You get hold of graph using CacheAttached event. See example below.

public class YourAttribute : PXEventSubscriberAttribute
{
    private PXGraph _Graph = null;

    public override void CacheAttached(PXCache sender)
    {
        _Graph = sender.Graph;    
        base.CacheAttached(sender);
    }
}
Nayan Mansinha
  • 291
  • 2
  • 4