acumatica - How to place a 'Related Entity' lookup on a field -


in activity / task screen (cr306020), there 'related entity' field pxselector lookup pencil opening screen of related entity:

enter image description here

i'd know if there way custom field. i've looked @ source code field (it's epactivity.source in dac), see nothing puts these attributes on field. no pxselector or similar.

the example below shows how add related entity field on opportunities (cr304000) screen. please aware, pxrefnoteselector control used in sample not supported layout editor in acumatica customization manager. used opportunities simplify , shorten example. unfortunately, can add related entity field on custom screen.

now let's move forward sample:

  1. implement extension cropportunity dac declare database bound usrrefnoteid , unbound relatedentity fields. related entity's noteid stored in usrrefnoteid, , relatedentity used 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     {                 {             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 opportunitymaint blc decorate primary opportunity data view pxrefnoteselectorattribute. pxrefnoteselectorattribute required edit (pencil) , lookup buttons work on 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 datafield property set relatedentity , noteiddatafield usrrefnoteid. editbutton, lookupbutton , lookuppanel tags, use primary data view name decorated pxrefnoteselector attribute (opportunity in 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 pxrefnoteselector attribute form toolbar. use same primary data view name decorated pxrefnoteselector attribute (opportunity in code snippet below) in 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 need implement own entitydescription operator, since @ time example created, had internal access modifier , not available outside of px.objects.dll:

public class entitydescription<refnoteid> : bqlformulaevaluator<refnoteid>, ibqloperand     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 customized opportunities screen brand-new related entity field:

enter image description here


Comments