In Employee Time Activity screen (EP307000) we can select project and project task in grid area.
Now we need to restrict project task selection base on login user’s roll.
In other word if login user have XYZ role then he can able to view only those task which contains “Labor” word in it.
So, basically PXSelector should be dynamic.
Best answer by darylbowman
This is a complicated-enough requirement that I think your best bet would be to create a custom selector for ProjectTasks. If you inherit PXCustomSelectorAttribute you can use the GetRecords() method to filter out records which you don’t want to return. These can get complicated, but here’s a simple example of how I used one:
public class NiceLabelLabelSelectorAttribute : PXCustomSelectorAttribute { public NiceLabelLabelSelectorAttribute() : base(typeof(NiceLabelLabel.itemPath)) { DescriptionField = typeof(NiceLabelLabel.labelName); }
protected virtual IEnumerable GetRecords() { var labelSetupGraph = PXGraph.CreateInstance<RXLabelSetupMaint>(); var labelSetup = labelSetupGraph.Setup.SelectSingle();
var labels = NiceLabelFunctions.GetLabels(labelSetup?.SubscriptionKey, labelSetup?.LabelFolderPath); if (labels is null) throw new PXException("No labels were returned from the NiceLabel service");
You can apply a PXRestrictor or define a custom selector attribute for the Project Task field. Make sure to implement this before the CacheAttached event is triggered for the field. This ensures that your restriction or custom logic is applied at the time the field is initialized and rendered on the screen.
You can apply a PXRestrictor or define a custom selector attribute for the Project Task field. Make sure to implement this before the CacheAttached event is triggered for the field. This ensures that your restriction or custom logic is applied at the time the field is initialized and rendered on the screen.
This is a complicated-enough requirement that I think your best bet would be to create a custom selector for ProjectTasks. If you inherit PXCustomSelectorAttribute you can use the GetRecords() method to filter out records which you don’t want to return. These can get complicated, but here’s a simple example of how I used one:
public class NiceLabelLabelSelectorAttribute : PXCustomSelectorAttribute { public NiceLabelLabelSelectorAttribute() : base(typeof(NiceLabelLabel.itemPath)) { DescriptionField = typeof(NiceLabelLabel.labelName); }
protected virtual IEnumerable GetRecords() { var labelSetupGraph = PXGraph.CreateInstance<RXLabelSetupMaint>(); var labelSetup = labelSetupGraph.Setup.SelectSingle();
var labels = NiceLabelFunctions.GetLabels(labelSetup?.SubscriptionKey, labelSetup?.LabelFolderPath); if (labels is null) throw new PXException("No labels were returned from the NiceLabel service");