Customizing Selector when another another Selector value changes

I need to Customize CaseClassID Selector on Cases Screen. It should refresh with different values when Contract field is selected on the CaseScreen under the Additional Info tab. Right now the CaseClass is displaying values from CRCase table.But, now if the contract changes the fieldupdatedEvent should be triggered and CaseClassID selector should have values accordingly. Please suggest me how to customize the CaseClassID selector inside FieldUpdated Event Handler

protected virtual void CRCase_ContractID_FieldUpdated(PXCache sender, 
      PXFieldUpdatedEventArgs e)
    {
        CRCase cc = (CRCase)e.Row;
        if (cc == null) return;
        CRCase_CaseClassID_CacheAttached(sender);
    }

[PXMergeAttributes(Method = MergeMethod.Replace)]
    [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
    [PXDefault(typeof(Search<CRSetup.defaultCaseClassID>))]
    [PXUIField(DisplayName = "Class ID")]
    [PXSelector(typeof(Search2<CRCaseClass.caseClassID, 
         InnerJoin<CaseContract, On<CaseContract.caseClassID, 
            Equal<CRCaseClass.caseClassID>>,
        InnerJoin<Contract, On<CaseContract.contractID, 
            Equal<Contract.templateID>>,
        InnerJoin<CRCase, On<Contract.contractID, 
            Equal<Current<CRCase.contractID>>>>>>,
        Where<CaseContract.active, Equal<True>>>),
               DescriptionField = typeof(CRCaseClass.description),
               CacheGlobal = true)]
    [PXMassUpdatableField]
    public virtual String CaseClassID { get; set; }
    public virtual void CRCase_CaseClassID_CacheAttached(PXCache sender){

    }

1 answer

  • answered 2018-01-11 21:01 HB_ACUMATICA

    Override CaseClassID selector and add your custom logic in its type parameter. You can create a custom unbound field to filter the selector according to your business logic. When you want to change selector filter, just change the custom field.

    #region CaseClassID
    public abstract class caseClassID : IBqlField { }
    
    [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
    [PXDefault(typeof(Search<CRSetup.defaultCaseClassID>))]
    [PXUIField(DisplayName = "Class ID")]
    // Use your custom field (filterCaseClassID) in the selector type parameter
    [PXSelector(typeof(Search<CRCaseClass.caseClassID,
                       Where<CRCaseClass.caseClassID, Equal<filterCaseClassID>>>),
                       DescriptionField = typeof(CRCaseClass.description), 
                       CacheGlobal = true)]
    [PXMassUpdatableField]
    public virtual String CaseClassID { get; set; }
    #endregion
    
    #region FilterCaseClassID
    public abstract class filterCaseClassID : IBqlField { }
    
    [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
    // Change the value of your custom field to set the selector filter
    public virtual String FilterCaseClassID { get; set; }
    #endregion
    

    EDIT overriding DAC field in graph extension and filtering Selector by using a field from another DAC:

    using PX.Data;
    using PX.Objects.CR.MassProcess;
    using System;
    
    namespace PX.Objects.CR
    {
        [Serializable]
        public class CaseContract : IBqlTable
        {
            public abstract class caseClassID : IBqlField { }
    
            [PXString(10, IsUnicode = true)]
            [PXUIField(DisplayName = "Case Class ID")]
            [PXSelector(typeof(CRCaseClass.caseClassID),
                        DescriptionField = typeof(CRCaseClass.description))]
            public virtual String CaseClassID
            {
                get; set;
            }
        }
    
        public class CRCaseMaint_Extension : PXGraphExtension<CRCaseMaint>
        {
            [PXMergeAttributes(Method = MergeMethod.Replace)]
            [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
            [PXDefault(typeof(Search<CRSetup.defaultCaseClassID>))]
            [PXUIField(DisplayName = "Class ID")]
            [PXSelector(typeof(Search<CRCaseClass.caseClassID,
                               Where<Current<CaseContract.caseClassID>, IsNull,
                               Or<CRCaseClass.caseClassID, Equal<Current<CaseContract.caseClassID>>>>>),
                        DescriptionField = typeof(CRCaseClass.description),
                        CacheGlobal = true)]
            [PXMassUpdatableField]
            public virtual void CRCase_CaseClassID_CacheAttached(PXCache sender)
            {
            }
        }
    }