Skip to main content

I have this customized selector attribute to filter Projects to the current customer on CRActivityMaint:

public class DSRestrictActivityProjects_CRActivityMaint_Ext : PXGraphExtension<CRActivityMaint>
{
[PXRemoveBaseAttribute(typeof(EPProjectAttribute))]
[CustomerProjects]
protected virtual void _(Events.CacheAttached<PMTimeActivity.projectID> e)
{ }

public class CustomerProjects : PXCustomSelectorAttribute
{
public CustomerProjects()
: base(typeof(PMProject.contractID),
typeof(PMProject.contractCD),
typeof(PMProject.description),
typeof(PMProject.status))
{
SubstituteKey = typeof(PMProject.contractCD);
DescriptionField = typeof(PMProject.description);
}

public virtual IEnumerable GetRecords()
{
CRActivity activity = (CRActivity)_Graph.Views["CurrentActivity"].Cache.Current;
if (activity is null || activity?.RefNoteID is null)
return null;

return SelectFrom<PMProject>.
LeftJoin<CRCase>.
On<CRCase.customerID.IsEqual<PMProject.customerID>>.
Where<PMProject.baseType.IsEqual<CTPRType.project>.
And<CRCase.noteID.IsEqual<@P.AsGuid>>>.
View.Select(_Graph, activity.RefNoteID).FirstTableItems;
}
}
}

It works fantastically, except that I can’t actually select a record.

What did I do wrong?

@darylbowman  Here is the solution for the above issue.

  1. Few modifications in the Custom Selector (For testing purposes, I have removed the Where condition and verified)
  2. In the .aspx page, Change the SegementMask to Selector control.

Here is the updated code.

public class DSRestrictActivityProjects_CRActivityMaint_Ext : PXGraphExtension<CRActivityMaint>
{
PXMergeAttributes(Method = MergeMethod.Append)]
PXRemoveBaseAttribute(typeof(EPProjectAttribute))]
CustomerProjects(typeof(PMProject.contractID))]
protected virtual void _(Events.CacheAttached<PMTimeActivity.projectID> e)
{ }

public class CustomerProjects : PXCustomSelectorAttribute
{
private PXView _view;
public CustomerProjects(Type type) : base(type, typeof(PMProject.contractCD),
typeof(PMProject.description),
typeof(PMProject.status))
{
SubstituteKey = typeof(PMProject.contractCD);
//DescriptionField = typeof(PMProject.description);
}


public virtual IEnumerable GetRecords()
{
//CRActivity activity = (CRActivity)_Graph.Viewss"CurrentActivity"].Cache.Current;
//if (activity is null || activity?.RefNoteID is null)
// return null;

return SelectFrom<PMProject>.
LeftJoin<CRCase>.
On<CRCase.customerID.IsEqual<PMProject.customerID>>.
Where<PMProject.baseType.IsEqual<CTPRType.project>
//And<CRCase.noteID.IsEqual<@P.AsGuid>>
>.
// View.Select(_Graph, activity.RefNoteID).FirstTableItems;
View.Select(_Graph).FirstTableItems.ToList();
}
}
}

 

 

 


You obviously spent some time on this. Thank you. I'll give it a shot.


I have two issues with your solution:

  1. I’m a little bit hesitant to change the field type. It seems like there would be a reason they used the field type they did, or issues if it were changed?
  2. I tried removing the ‘where’, and while it does show projects, it does not show only projects for the current Customer if the current Activity is tied to a Case, which was the original goal

So using your observations, I instead tried implementing a customized PXDimensionSelector like this:

public class CustomerProjects2 : PXCustomDimensionSelectorAttribute
{
public CustomerProjects2()
: base("PROJECT", typeof(PMProject.contractID),
typeof(PMProject.contractCD),
typeof(PMProject.contractCD),
typeof(PMProject.description),
typeof(PMProject.status))
{ }

public override IEnumerable GetRecords()
{
CRActivity activity = (CRActivity)*noGraph*.Views."CurrentActivity"].Cache.Current;
if (activity is null || activity?.RefNoteID is null)
return null;

return SelectFrom<PMProject>.
LeftJoin<CRCase>.
On<CRCase.customerID.IsEqual<PMProject.customerID>>.
Where<PMProject.baseType.IsEqual<CTPRType.project>.And<CRCase.noteID.IsEqual<@P.AsGuid>>>.
View.Select(new PXGraph(), activity.RefNoteID).FirstTableItems;
}
}

The problem is, there is no ‘_Graph’ attribute that I can find to allow getting the current Activity, which means the results are not filtered.

I also can’t find any documentation for this situation.


@darylbowman  I don’t think those are the issues, which I have provided and that is one of the solutions to resolve your issues.

As you mentioned about “DimensionSelector”, you can also use my solution with the DimensionSelector, so that we can use the SegmentMask instead of Selector.

but yes, PXCustomDimensionSelectorAttribute we will not have the _Graph, and I never tried with this.

I recommend you to raise a support case with Acumatica.

 

 


Hi.

I’m incredibly late to the party, but my team found this topic when they were trying to resolve a similar issue.

In case someone else stumbles upon this, we’ve seen the issue that using the private PXGraph field with setting it in the CacheAttached didn’t help them because the value of the field was resetting somewhere along the way.

Here’s the solution that worked:

        public class SampleDimensionSelectorAttribute : PXDimensionSelectorAttribute
{
private const string _dimension = "SAMPLE";
private const Type _type = typeof(SampleDac.SampleDacID);
private const Type _substituteKey = typeof(SampleDac.SampleDacCD);
private const Typec] _fieldList = new Type=]
{
typeof(SampleDac.SampleDacCD),
typeof(SampleDac.descr)
};

public SampleDimensionSelectorAttribute() : base(_dimension, _type, _substituteKey, _fieldList)
{
PXSelectorAttribute item = new SampleSelectorAttribute(_type, _fieldList)
{
SubstituteKey = _substituteKey
};
_Attributes.RemoveAt(_Attributes.Count - 1);
_Attributes.Add(item);
}

private class SampleSelectorAttribute : PXCustomSelectorAttribute
{
public SampleSelectorAttribute(Type searchType)
: base(searchType)
{
}

public SampleSelectorAttribute(Type searchType, TypeT] fieldList)
: base(searchType, fieldList)
{
}

public IEnumerable GetRecords()
{
if (!(_Graph.Cachesanameof(SampleSetup)].Current is SampleSetup sampleSetup))
return Enumerable.Empty<SampleDac>();

if (sampleSetup.UsrIBSampleSetup.GetValueOrDefault() == true)
{
return new PXSelect<SampleDac, Where<SampleDac.sampleFlag, Equal<True>>>(_Graph).Select();
}
else
{
return new PXSelect<SampleDac, Where<SampleDac.sampleFlag, Equal<False>>>(_Graph).Select();
}

return Enumerable.Empty<SampleDac>();
}
}
}

 


Interesting. You’re swapping the selector attribute for a custom one. Very cool.


Reply