Trying to update in a custom action a custom field I added to Customer Location
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)] rPXUIField(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 CPXDBDecimal] 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…
Page 1 / 1
Hi @edwardmcgovern97,
You have to assign value to the extended DAC field like below.
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?
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
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.
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:
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:
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)
And image to drive the point home what I am trying to do
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.
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.