Question

Why does this customized selector attribute not allow selection?

  • 4 February 2023
  • 4 replies
  • 96 views

Badge +11

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?


4 replies

Userlevel 7
Badge +17

@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.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;
View.Select(_Graph).FirstTableItems.ToList();
}
}
}

 

 

 

Badge +11

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

Badge +11

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.

Userlevel 7
Badge +17

@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.

 

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved