0

In the Activity / Task screen (cr306020), there is a 'Related Entity' field with a PXSelector lookup as well as a pencil for opening the screen of the related entity:

enter image description here

I'd like to know if there is a way to do this for a custom field. I've looked at the source code for the field (it's EPActivity.Source in the DAC), but I see nothing that puts these attributes on that field. No PXSelector or anything similar.

pmfith
  • 831
  • 6
  • 24
  • Are you looking to simply add the pencil icon (form) / hyper link (grid column) to a field that when clicked takes you to another page? See if this post gives you what you need: http://stackoverflow.com/questions/26387291/how-to-create-a-hyperlink-user-field/34190669#34190669 – Brendan Apr 05 '17 at 18:29

1 Answers1

0

The example below shows how to add the Related Entity field on the Opportunities (CR304000) screen. Please be aware, PXRefNoteSelector control used in this sample is not currently supported by the Layout Editor in Acumatica Customization Manager. I used Opportunities to simplify and shorten the example. Unfortunately, for now you can only add the Related Entity field on a custom screen.

Now let's move forward to the sample:

  1. Implement extension for the CROpportunity DAC to declare the database bound UsrRefNoteID and unbound RelatedEntity fields. Related Entity's NoteID will be stored in UsrRefNoteID, and RelatedEntity will be used to display Related Entity's user-friendly description:

    public class CROpportunityExt : PXCacheExtension<CROpportunity>
    {
        #region UsrRefNoteID
        public abstract class usrRefNoteID : IBqlField { }
    
        protected Guid? _UsrRefNoteID;
    
        [PXDBGuid]
        [PXParent(typeof(Select<CRActivityStatistics,
            Where<CRActivityStatistics.noteID, Equal<Current<CROpportunityExt.usrRefNoteID>>>>), LeaveChildren = true)]
        public Guid? UsrRefNoteID
        {
            get
            {
                return _UsrRefNoteID;
            }
            set
            {
                _UsrRefNoteID = value;
            }
        }
        #endregion
    
        #region Source
        public abstract class relatedEntity : IBqlField { }
    
        [PXString(IsUnicode = true)]
        [PXUIField(DisplayName = "Related Entity Description", Enabled = false)]
        [PXFormula(typeof(EntityDescription<CROpportunityExt.usrRefNoteID>))]
        public string RelatedEntity { get; set; }
        #endregion
    }
    
  2. Create extension for the OpportunityMaint BLC to decorate its primary Opportunity data view with PXRefNoteSelectorAttribute. The PXRefNoteSelectorAttribute is required for the Edit (pencil) and Lookup buttons to work on your custom Related Entity field:

    public class OpportunityMaintExt : PXGraphExtension<OpportunityMaint>
    {
        [PXCopyPasteHiddenFields(typeof(CROpportunity.resolution))]
        [PXViewName(Messages.Opportunity)]
        [PXRefNoteSelector(typeof(CROpportunity), typeof(CROpportunityExt.usrRefNoteID))]
        public PXSelect<CROpportunity> Opportunity;
    }
    
  3. On Aspx page, add PXRefNoteSelector control with the DataField property set to RelatedEntity and NoteIDDataField to UsrRefNoteID. For the EditButton, LookupButton and LookupPanel tags, use the primary data view name decorated with the PXRefNoteSelector attribute (Opportunity in the code snippet below)

    <pxa:PXRefNoteSelector ID="edRefEntity" runat="server" DataField="RelatedEntity" NoteIDDataField="UsrRefNoteID"
        MaxValue="0" MinValue="0" ValueType="Guid" CommitChanges="true">
        <EditButton CommandName="Opportunity$Navigate_ByRefNote" CommandSourceID="ds" />
        <LookupButton CommandName="Opportunity$Select_RefNote" CommandSourceID="ds" />
        <LookupPanel DataMember="Opportunity$RefNoteView" DataSourceID="ds" TypeDataField="Type" IDDataField="NoteID" />
    </pxa:PXRefNoteSelector>
    
  4. Hide 3 actions generated by the PXRefNoteSelector attribute from the form toolbar. Use the same primary data view name decorated with the PXRefNoteSelector attribute (Opportunity in the code snippet below) as in the step above:

    <CallbackCommands>
        ...
        <px:PXDSCallbackCommand Name="Opportunity$Navigate_ByRefNote" Visible="False" />
        <px:PXDSCallbackCommand Name="Opportunity$Select_RefNote" Visible="False" />
        <px:PXDSCallbackCommand Name="Opportunity$Attach_RefNote" Visible="False" />
    </CallbackCommands>
    

You might also need to implement your own EntityDescription operator, since at the time this example was created, it had internal access modifier and was not available outside of the PX.Objects.dll:

public class EntityDescription<RefNoteID> : BqlFormulaEvaluator<RefNoteID>, IBqlOperand
    where RefNoteID : IBqlField
{
    public override object Evaluate(PXCache cache, object item, Dictionary<Type, object> pars)
    {
        Guid? refNoteID = (Guid?)pars[typeof(RefNoteID)];
        return new EntityHelper(cache.Graph).GetEntityDescription(refNoteID, item.GetType());
    }
}

And finally... screenshot of the customized Opportunities screen with a brand-new Related Entity field:

enter image description here

RuslanDev
  • 6,718
  • 1
  • 14
  • 27
  • Thanks much, Ruslan - I'll give it a try soon. – pmfith Apr 10 '17 at 15:44
  • Not sure if you still monitor this, Ruslan - but I'm confused about the CRActivityStatistics in your example. What does this refer to, and how is it relevant to your example? I guess I'm asking what the purpose is of the PXParent attribute in the declaration of UsrRefNoteID... – pmfith Mar 26 '20 at 20:21