SOLine apply business logic (AKA update price) after updating the orderQty - acumatica

I've created some code that uses a number of fields (eg: length, width, LbsPerInch) to calculate the order quantity. I've used this:
cache.SetValue<SOLine.orderQty>(e.Row, dQO);
That part work perfectly. After that's updated, I need to have the line update the rest of the line as though the orderQty was updated manually.
I tried using the following, but that must not be correct, as it seems to just completely hand the form when it runs.
Base.Transactions.Update(row);
Base.Transactions.View.RequestRefresh();
Thanks in advance!

When the user modifies a field on screen it raises the FieldUpdated event for that field.
The base graph you are extending can declare handlers for these FieldUpdated events. The issue could be that the OrderQty field events aren't raised and the base graph uses those events to update other fields which values depend on OrderQty.
The SetValue method changes field value without raising field events.
The SetValueExt method changes field value and raises field events.
You can try using SetValueExt instead of SetValue:
cache.SetValueExt<SOLine.orderQty>(e.Row, dQO);
This is usually sufficient. The most stubborn refresh issues can usually be dealt with by calling the RaiseRowUpdated method to raise the row events after the field has been modified.

Related

SumCalc attribute not working when trying to summarize usr Field from PMTask to PMProject

First, created a custom field in the PM.PMTask DAC called usrNumberofPanel
Second, created a custom field in the PM.PMProject DAC usrTotalPanels.
Want each of the lines from task to update the total number of panels on the project, so modified the attribute for PM.PMTask.userNumberofPanel and added a PXFormula as shown below to add the SumCalc.
[PXDBDecimal]
[PXUIField(DisplayName="Number of Panels")]
[PXFormula(null, typeof(SumCalc<PX.Objects.CT.ContractExt.usrTotalPanels>))]
Made sure the attributes for the Total Panel and set as follows to make sure no one types into the field.
[PXDBDecimal]
[PXUIField(DisplayName="Total Panels", Enabled = false)]
Any thoughts would be appreciated.
It's a known issue that SumCalc doesn't work properly across DACs that are linked with PXParent relationships.
I can only recommend to use a RowSelected or FieldSelecting graph event handlers to compute the sum instead of a solution involving DAC attributes. You can add a comment explaining the limitation of DAC attributes in the event handler if you are seeking Acumatica ISV Certification for your solution.

ID error when inserting row into Acumatica view

I have a row of data (type InventoryItem) that originated from a different Acumatica instance db. I want to simply insert it using the InventoryItemMaint.Item view. I cleared out the originating InventoryID value first since it's an identity column. I tried both nulling it out and setting it to zero. Whatever I set it to, it throws a PXFieldValueProcessingException that the InventoryID can't be found; but of course it's not supposed to be found, it's supposed to be generated when inserted into the db. The code simply does:
graph.Item.Insert(row);
The error message also mentions the DfltSiteID field. Does it maybe fire all field update events when I call view.Insert() and an event handler might unsafely reference InventoryID? Any ideas what I'm missing?

Selector shows ID instead of CD after exception

I am trying to filter the Case classes based on the contract selected. If a wrong Case class is selected for particular contract then I am throwing an exception on Class ID field.
Below is the line of code I have used to throw an exception
throw new PXSetPropertyException<CRCase.caseClassID>("Incorrect Case Class for Contract");
After the exception, the selector shows ID instead CD value. can anyone tell me why?
It would be helpful to have more detail, like the whole function where you added your code.
Depending on where you are throwing that exception, you may be cancelling the event sequence.
The events for trigger in certain order, and the PXSelector attribute uses DAC events to update and subtitute the field value in the UI with the display value.
Try moving your exception to the FieldValidating event method in the graph.

Restrict User input for PXSelector and use it only as a lookup

I have a case in my customisation project, were I have a PXSelector that I want it to solely act as a lookup, and would not like the users to input any data via the selector and create new records.
I could not find a way to limit this from the attribute itself, therefore I tried to limit it from the events that the control fires. The idea was that in the FieldUpdating Event I would verify whether the value inserted by the user can be found in the selector's key column, if not I would revert it back to the old value. The problem was that cancelling the event had no effect on the selector and since I did not know what the previous value was, I could not revert it back manually.
It sounds like you are trying to use a filter. You need a PXFilter view which then could be used to display data in a grid for example.
You can search the source for "PXFilter to find good examples. One I found is APVendorBalanceEnq which uses public PXFilter<APHistoryFilter> Filter
PXFilter views are not committed to the database. Typically you would create a new DAC for the filter based on your needs but you can use existing DACs that are bound to tables without the fear of the data making it to the database. With the filter you simply use the field values rather than load records into the view.

Acumatica Requisition Total Cost Custom Calculation

I've added three custom decimal? field on Requisition master (RQ302000) and need to prorate the total value of those three fields to the each Requisition line using line base total cost/master total cost ratio and displayed the result as Additional Cost (also custom decimal? field) of each line.
This calculation should be triggered when those three new field are updated.
What I don't understand are:
1. What events should be modify related to this needs
2. If it is event on master field, how to get value from line extension field
3. If it is event on line field, how to get value from master extension field
Requisition Custom Screen
1. "What events should be modify related to this needs?"
In a scenario, like yours, one should use combination of RowInserted, RowUpdated and RowDeleted handlers:
The RowInserted event handler is used to implement the business logic for:
Inserting the detail data records in a one-to-many relationship.
Updating the master data record in a many-to-one relationship.
Inserting or updating the related data record in a one-to-one relationship.
The RowUpdated event handler is used to implement the business logic of:
Updating the master data record in a many-to-one relationship.
Inserting or updating the detail data records in a one-to-many relationship.
Updating the related data record in a one-to-one relationship.
The RowDeleted event handler is used to implement the business logic of:
Deleting the detail data records in a one-to-many relationship.
Updating the master data record in a many-to-one relationship.
Deleting or updating the related data record in a one-to-one relationship.
Also FieldUpdated handlers be considered for your scenario:
The FieldUpdated event handler is used to implement the business logic associated with changes to the value of the DAC field in the following cases:
Assigning the related fields of the data record containing the modified field their default values or updating them
Updating any of the following:
The detail data records in a one-to-many relationship
The related data records in a one-to-one relationship
The master data records in a many-to-one relationship
Refer to API Reference in Help -> Acumatica Framework -> API Reference -> Event Model and T200 developer class for additional information and examples on Acumatica Framework event model.
2. "If it is event on master field, how to get value from line extension field?"
In Acumatica custom fields are declared via DAC extensions. To access the DAC extension object, you can use the following methods:
The GetExtension() generic method available for each DAC instance:
ContactExt contactExt = curLead.GetExtension<ContactExt>();
The GetExtension(object) generic method declared within the non-generic PXCache class
ContactExt contactExt = Base.LeadCurrent.Cache.GetExtension<ContactExt>(curLead);
or
ContactExt contactExt = Base.Caches[typeof(Contact)].GetExtension<ContactExt>(curLead);
The GetExtension(object) static generic method of the PXCache generic class
ContactExt contactExt = PXCache<Contact>.GetExtension<ContactExt>(curLead);
To get value from line extension field, you should first select records from the Lines data view, then use one of the methods described above to access instance of DAC extension class, for instance:
foreach(RQRequisitionLine line in Base.Lines.Select())
{
RQRequisitionLineExt lineExt = line.GetExtension<RQRequisitionLineExt>();
}
3. "If it is event on line field, how to get value from master extension field"
That's an easy one: same 3 approaches described above, this time applied to Current property of the primary Document data view, for instance:
Base.Document.Current.GetExtension<RQRequisitionExt>();

Resources