My background is C#, T-SQL, and ORMs like EF. I’m continually having issues wrapping my head around the Acumatica paradigm. Something as simple as conditionally adding a row to the DB with the user’s ID (if one isn’t present) to a custom master table (UserPriceComparison) escapes me.
And then, I need to re-save the row whenever the user changes the form - and also refresh the details view.
The reason for all of the above is that the complex pivot and aggregation logic I need to create is not performant anywhere except inside of a T-SQL view, which uses the values in the master table to do thing that I can’t explain here.
While my instinct is to ask the question, I can predict that the first thing that will happen is that someone will ask to see my code. Pretend I don’t have any. This should be, what, 10 lines of code at most?
private void CreateFilterWhenMissing() // Call on load? Or later.
{
var u = PXAccess.GetUserID();
// Get the existing row for the current user
EmpPriceComparisonUser row = SelectFrom<EmpPriceComparisonUser>.Where<EmpPriceComparisonUser.userId.IsEqual<@P.AsGuid>>.View.Select(this, u);
if (row != null)
{
return;
}
row = new EmpPriceComparisonUser();
row.UserId = u;
Caches[typeof(EmpPriceComparisonUser)].Insert(row);
}