Solved

Trying to update in a custom action a custom field I added to Customer Location

  • 19 October 2022
  • 8 replies
  • 456 views

Userlevel 3
Badge

on the Customer Location screen I have added two new tables and new DACs of course and I have modified the Location table to have a few custom fields.  I have added the Location_Ext to the Visual studio project after adding the fields.  

The screen allows me to update the custom fields all day long. 

But I am trying to create a custom action to loop my custom table and put the total of one of the fields in there.  I don’t think I have a problem looping the table.  It uses the view I added for the screen and seems to work but trying to put the total in Location.UsrSettlementAmt.  

I don’t see a Location.UsrSettlementAmt.  What gives? 

Below is the custom action. 

public PXAction<Location> CalculateSettlement;
        [PXButton(DisplayOnMainToolbar = true)]
        [PXUIField(DisplayName = "Settlement Total", Enabled = true)]
        protected virtual void calculatesettlement()
        {
            decimal? d = 0;
            foreach (SettlementDetail sd in InvoiceSettlement.Select())
            {
                d = d + sd.DetailAmt;
            }
            

        }

This is the definition of the custom field in the DAC: 


namespace PX.Objects.CR
{
  public class LocationExt : PXCacheExtension<PX.Objects.CR.Location>
  {
    #region UsrSettlementAmt
            [PXDBDecimal]
    [PXUIField(DisplayName="Settlement Amount")]
 

I have tried changing the namespace to LocationTab (same as rest of project) to no avail

 

Any help would be appreciated…

 

 

icon

Best answer by edwardmcgovern97 21 October 2022, 21:31

View original

8 replies

Userlevel 6
Badge +3

Hi @edwardmcgovern97,

You have to assign value to the extended DAC field like below.

Location.Current.GetExtension<LocationExtn(extensionDACName)>(). UsrSettlementAmt  = <Your Value>;

 

Userlevel 3
Badge

Interesting.  I think I am having problems with that statement because the Location field is the name of the DAC and the View used by the Customer Location Form (when I inspect the form and look at the existing dac).  They seem to be the same.  

This is an existing form also.  So I can’t see the definition of the view in Visual Studio.  

Either way I try to Reference Location  and there is no Location.Current like I get for a view?  

So on a more elemental level how do I get the current record when I am modifying the form in Visual Studio and trying to add custom Action? 

I can’t reference   ViewName.Current to get the current record.  Or am I missing something?

 

Userlevel 3
Badge

I am trying to use the refrerence 

LocationMaint.Location.Current.GetExtension<UsrSettlementAmt>  = val;

And its not erroring.  It has the Current reference, resolves to a view and is the definition of the view from the form I am modifing (checked the code in app_data). 

Also not updating the field lol

Not sure what the update command is for the view

 

Userlevel 4
Badge +1

Hi @edwardmcgovern97,

  Please try the below way to get a custom field value.

  var fieldValue = PXCache<DACName>.GetExtension<DACNameExt>(row).UsrFieldName;

 

Hope this may help you.

 

Thanks,

Moulali Shaik.

Userlevel 3
Badge

Hey Moulali, thanks for the response. 

I am not updating the grid, so there is no row to reference

This is a custom Action that loops the grid contents and updates a custom field, not on the grid in the header of the form.  

I have been kind of down your path (using PXCache - been looking at other screens and examples online) 

And the way I got at the Veiw for the existing form I’m modifying is like this: 

 Location loc = (Location)Base.Location.Current;

So with that I think I am clear to update the Data brought in from the Location view on the screen using PXCache like so: 

PXCache<Location>.GetExtension<LocationExt>(loc).UsrSettlementAmt = (decimal?)25.00;

The thing I am having an issue with 

is that after I run the Action The Control on the screen that holds the UsrSettlementAmt amount does not change values and the form doesn’t make the save button active, meaning it has no idea I updated the Cache…

So my code now looks like this for the custom action: 

 public PXAction<Location> CalculateSettlement;
        [PXButton(DisplayOnMainToolbar = true)]
        [PXUIField(DisplayName = "Settlement Total", Enabled = true)]
        protected virtual void calculatesettlement()
        {            

            decimal? d = 0;
            foreach (SettlementDetail sd in InvoiceSettlement.Select())
            {
                d = d + sd.DetailAmt;
            }

            //(Location)Base.
            Location loc = (Location)Base.Location.Current;

            PXCache<Location>.GetExtension<LocationExt>(loc).UsrSettlementAmt = (decimal?)25.00;
            


        }

 

Once again my problem is how do get the Cache to display on the screen with the new updated values AND recognize that the values updated and make the save active (or save my cache to the database and refresh back to sceen if I must) 

 

Userlevel 3
Badge

And image to drive the point home what I am trying to do

 

Userlevel 4
Badge +1

Hi @edwardmcgovern97

 

Please try the below way to update the custom field value inside an action method.

Ex:

#region Actions
public PXAction<YourDac> SomeValue;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "some name")]
protected virtual void someValue()
{
 // Get the current record from the cache.
 var row = YourDataView.Current;

// Get the DacExt 
var rowExt = row.GetExtension<YourDacExt>();

OR

var rowExt = cache.GetExtension<YourDacExt>(row);

 
 // Change the custom field value
 rowExt.usrField = someValue
 
 
 // Update the data record in the cache.
 DataView.Update(rowExt);
 
 // Trigger the Save action to save changes in the database.
 Actions.PressSave();
}
#endregion

 

 

Hope this may help you.

Thanks,

Moulali Shaik.

 

Userlevel 3
Badge

Thanks, but i am not doing this in a grids event, so there is no row object. 

I figured it out, my code I did the other day did worked, it just wasn’t detecting the changes for some reason in my dll for the project when I tried to deploy?  

When properly deployed the code below does exactly what I need.  It updates the field and saves it.  

 

public PXAction<Location> CalculateSettlement;
        [PXButton(DisplayOnMainToolbar = true)]
        [PXUIField(DisplayName = "Settlement Total", Enabled = true)]
        protected virtual void calculatesettlement()
        {            

            decimal? d = 0;
            foreach (SettlementDetail sd in InvoiceSettlement.Select())
            {
                d = d + sd.DetailAmt;
            }

            //(Location)Base.
            Location loc = (Location)Base.Location.Current;

            PXCache<Location>.GetExtension<LocationExt>(loc).UsrSettlementAmt = d;
            


        }

 

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