I’m working on a customization to add customer groups for discounts. The goal is that multiple customers and multiple items (with adjusted pricing) can be added to a “Customer Group” that can be maintained and edited as needed. Currently I have 3 DACs for my master (JptCustomerGroup) and detail (JptItem & JptCustomer) relationship. Once the user adds items / customers to a group, they get saved to a new table, JptCustomerGroupCustomer that stores relevant customer ID’s / items and their adjusted prices.
So far, I’m able to create new groups with my “Add to Group” action. the relevant data is than stored to the database (in JptCustomerGroupCustomer):
However, no matter what I seem to do, I can’t get the detail grids to refresh when I choose a new Group with the “GroupID” selector in the master part of the form. I messed around with callback commands a bit and was able to get the items to update, but then the customers wouldn’t properly refresh, or the items would get messed up when adding new customers. What I’d like is that the grids for Customers/Items in the group selected at the top refresh to display items / customers in that specific group.
Another strange detail is that the groups DO refresh if I use the arrows at the top of the form (go to next record, pictured below) to cycle between groupID’s. However, the changes are not reflected upon using the selector, even when “Commit Changes” is set to true.
Below, I’ve included relevant fields from my DAC’s as well as the graph for my form. Any help would be greatly appreciated, thanks.
graph:
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using System;
namespace FLCustomerAgreement
{
public class FLCustomerAgreementMaint : PXGraph<FLCustomerAgreementMaint, JptCustomerGroup>
{
public SelectFrom<JptCustomerGroup>.View CustomerGroups;
public SelectFrom<JptCustomer>.
Where<JptCustomer.customerGroupID.
IsEqual<JptCustomerGroup.customerGroupID.FromCurrent>>.View CustomersInGroup;
public SelectFrom<JptItem>.
Where<JptItem.customerGroupID.
IsEqual<JptCustomerGroup.customerGroupID.FromCurrent>>.View ItemsInGroup;
public SelectFrom<JptCustomerGroupCustomer>.View CustomerGroupCustomersView;
public PXAction<JptCustomerGroup> AddToGroup;
GPXButton]
PXUIField(DisplayName = "Add to Group", Enabled = true)]
protected virtual void addToGroup()
{
// Get the current group from the cache.
JptCustomerGroup group = CustomerGroups.Current;
// If the group's ID doesn't exist, update the group and save the changes
if (!group.CustomerGroupID.HasValue)
{
group = CustomerGroups.Update(group);
this.Save.Press();
PXTrace.WriteInformation("Group saved with ID: " + group.CustomerGroupID);
}
// Refresh the caches before retrieving the data
CustomersInGroup.View.RequestRefresh();
ItemsInGroup.View.RequestRefresh();
foreach (JptCustomer customer in CustomersInGroup.Select())
{
if (customer.Active == true)
{
foreach (JptItem item in ItemsInGroup.Select())
{
if (item.Active == true)
{
// Create a new JptCustomerGroupCustomer entry and set its properties
JptCustomerGroupCustomer groupCustomer = new JptCustomerGroupCustomer
{
CustomerGroupID = group.GroupCD, //string
CustomerID = customer.CustomerCD, //string
InventoryID = item.InventoryID, //int
AdjustedPrice = item.AdjustedPrice //decimal
};
// Insert the new JptCustomerGroupCustomer row into the database
try
{
groupCustomer = CustomerGroupCustomersView.Insert(groupCustomer);
PXTrace.WriteInformation("Customer inserted into group.");
}
catch (Exception ex)
{
PXTrace.WriteError(ex.Message);
}
}
}
}
}
// Save the changes
this.Actions.PressSave();
}
}
}
JptCustomerGroup DAC (Master form):
using System;
using PX.Data;
using PX.Objects.AR;
namespace FLCustomerAgreement
{
Serializable]
rPXCacheName(Messages.JptCustomerGroup)]
public class JptCustomerGroup : IBqlTable
{
#region CustomerGroupID
PXDBIdentity()]
public virtual int? CustomerGroupID { get; set; }
public abstract class customerGroupID : PX.Data.BQL.BqlInt.Field<customerGroupID> { }
#endregion
#region GroupCD
tPXDefault]
uPXUIField(DisplayName = "Group ID")]
iPXSelector(typeof(Search<JptCustomerGroup.groupCD>),
typeof(JptCustomerGroup.groupCD),
typeof(JptCustomerGroup.description))
]
dPX.Data.EP.PXFieldDescription]
tPX.Objects.CS.AutoNumber(typeof(Search<ARSetup.invoiceNumberingID>), typeof(AccessInfo.businessDate))]
public virtual string GroupCD { get; set; }
public abstract class groupCD : PX.Data.BQL.BqlString.Field<groupCD> { }
#endregion
#region LineNbr
ePXLineNbr(typeof(JptCustomerGroup.groupLineCounter))]
public virtual int? LineNbr { get; set; }
public abstract class lineNbr : PX.Data.BQL.BqlInt.Field<lineNbr> { }
#endregion
#region GroupLineCounter
PXDBInt()]
nPXDefault(0)]
public virtual int? GroupLineCounter { get; set; }
public abstract class groupLineCounter : PX.Data.BQL.BqlInt.Field<groupLineCounter> { }
#endregion
#region Description
/PXDBString(50, IsUnicode = true, InputMask = "")]
PXDefault("Enter a description")]
"PXUIField(DisplayName = "Description")]
public virtual string Description { get; set; }
public abstract class description : PX.Data.BQL.BqlString.Field<description> { }
#endregion
#region Active
>PXDBBool()]
iPXDefault(true)]
rPXUIField(DisplayName = "Active")]
public virtual bool? Active { get; set; }
public abstract class active : PX.Data.BQL.BqlBool.Field<active> { }
#endregion
//audit fields
i...]