Solved

Need help getting a custom field to show a value in a grid

  • 28 April 2023
  • 4 replies
  • 307 views

Userlevel 7
Badge +3

I have several custom fields on the Cost Budget tab of the Projects screen.  5 of them are stored in the DB and they are working great.  

My issue is getting a non bound field to display a value in the grid.  I want to pull the Task Description field from the PMTask table and display it.

I debugged the rowselected event on the PMCostBudget cache and there is a correct value in the PMCostBudget.projectTaskID field.   

    public class ProjectEntry_Extension : PXGraphExtension<PX.Objects.PM.ProjectEntry>
    {
        #region Event Handlers
        protected void PMCostBudget_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            var row = (PMCostBudget)e.Row;

            //PMCostBudget.projectTaskID = 1697

        }
        #endregion
    }

 

The DAC extension for this field is as follows

    public class PMBudgetExt : PXCacheExtension<PX.Objects.PM.PMBudget>
    {

       Not showing the 5 db fields here for brevity - they work fine.

        #region UsrTaskDescription
        [PXString(250, IsUnicode = true)]
        [PXUIField(DisplayName = "Task Description", Enabled = false)]
        [PXDefault(typeof(Select<PMTask, Where<PMTask.taskID, Equal<Current<PMCostBudget.projectTaskID>>>>), SourceField = typeof(PMTask.description), PersistingCheck = PXPersistingCheck.Nothing)]
        public virtual string UsrTaskDescription { get; set; }
        public abstract class usrTaskDescription : PX.Data.BQL.BqlString.Field<usrTaskDescription> { }
        #endregion

    }

I am trying to get the description field as shown in the PXDefault above.

Is there something wrong with the code?  It looks like it should do what I want, but the grid shows a blank field

 

 

 

icon

Best answer by aaghaei 28 April 2023, 20:26

View original

4 replies

Userlevel 7
Badge +9

@Joe Schmucker 

You can do it in two ways.

Either Instead of PXDefault use PXFormula at DAC level or add a Field Selecting Event for you custom field in the graph ext.

Userlevel 7
Badge +3

@aaghaei Thank you.  I don’t know how to do formulas, so I went with the RowSelected handler to do it.

        protected void PMCostBudget_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            var row = (PMCostBudget)e.Row;
            if (row == null) return;

            PMBudgetExt ext = row.GetExtension<PMBudgetExt>();

            PMTask task = SelectFrom<PMTask>.Where<PMTask.taskID.IsEqual<PMCostBudget.projectTaskID.FromCurrent>>.View.Select(Base);

            if (task == null) return;

            ext.UsrTaskDescription = task.Description;
            ext.UsrCostSubAccount = task.DefaultExpenseSubID;
        }

I tried to avoid using rowselected because I think it is frowned upon to use BQL statements in row selected.  

I also set commitchanges = true on the TaskID field so that for a new row, it would display the values.

Thank you for your advice!

 

Userlevel 7
Badge +9

@Joe Schmucker  If you set the below Property on your custom field (UsrTaskDescription) in your Cost Budget will do the work and you will not make your Cache Dirty in RowSelected. You can do the same for UsrCostSubAccount 

 

        [PXFormula(typeof(Search<PMTask.description,
Where<PMTask.projectID.IsEqual<PMCostBudget.projectID.FromCurrent>
.And<PMTask.taskID.IsEqual<PMCostBudget.projectTaskID.FromCurrent>>>>))]

The other best alternative option I believe will be FieldSelecting Event of UsrTaskDescription

Userlevel 7
Badge +3

@aaghaei That PXFormula compiles!  Better than I could do!  When I remove the rowselected handler I created an put that PXFormula into my DAC, it still doesn’t bring up the description.  However, the way I have it now is working and after spinning my wheels for 5 hours, I will settle for what I’ve got right now.

I’m going to keep that code snip in my project commented out so I can look back to it in the future.  Thanks for giving me sample code on how to do a PXFormula!

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