Property for PXProcessing row - acumatica

I have a processing page that I want to automatically select certain types of rows. I can set the select checkbox to true, but what property needs to be set on the row so that the process button will act on it? Right now nothing happens unless I check another row.
public void EDASNShipProj_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
PXUIFieldAttribute.SetDisplayName<EDASNShipProj.customerLocationID>(sender, "Ship Location");
var row = (EDASNShipProj)e.Row;
if ( row.UsrTruckNbr != 0 )
row.Selected = true;
PXUIFieldAttribute.SetVisible<SOShipment.selected>(sender, null, true);
}

I figured this out after searching the base source code for ".Selected=true". I found several places which included two extra lines. I added them to my condition and now the checked rows are included in the process list. Hopefully this will help others.
if (row.UsrTruckNbr != 0)
{
row.Selected = true;
sender.IsDirty = true;
sender.SetStatus(row, PXEntryStatus.Updated);
}

Related

Hiding value of a selector in a grid dynamically

I am trying to hide these duplicate inventory ID values for the "price" and "Cost" lines (when one "adds" an item to the grid it creates three lines), but the selector description still appears.
How can I just make these value come up blank in the grid?
Even better, how can I disable a link command so if someone inadvertently clicks then it wont link to the stock item screen?
Here is my code thus far:
protected void _(Events.FieldSelecting<FPPriceSheetDetail, FPPriceSheetDetail.inventoryID> e)
{
if (e.Row is null) return;
if (e.Row.RowType == FPPriceSheetRowType.BreakQty) return;
var state = PXFieldState.CreateInstance(e.ReturnState, typeof(string), true, false, 1, null, null, null, nameof(FPPriceSheetDetail.inventoryID));
state.SelectorMode = PXSelectorMode.TextMode;
state.DescriptionName = "";
state.ValueField = "";
state.Visibility = PXUIVisibility.Visible;
state.Visible = true;
e.ReturnState = state;
e.ReturnValue = "";
}
I would rather review the pxSelector and in the condition only show 1-row type - this will remove the duplicates. The point of the selector is to select one of the values within the result - assuming all the information the selector are selectable.

How can i load dropdown values dynamically in acumatica for each row with different dropdown values?

Example:
As per the Below screenshot, i have to combine below two grids into one grid and the first grid(query list) will display as it is and the second grid values should show as drop down for the respective query.
Samplegridsimage
when i tried to use field selecting event, it is loading all vales from second grid but i need only 3 values for fuel type value and for others different drop down.
can anyone suggest how to get only particular values in the drop down.
protected virtual void KNRWTAXQueries_Response_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
KNRWTAXQueries doc = e.Row as KNRWTAXQueries;
if (doc == null) return;
List<string> Responsevalues = new List<string>();
List<string> ResponseLables = new List<string>();
if (QueryList.Current != null)
{
if (Base.Transactions.Current != null)
{
foreach (KNRWTAXQueries queries in PXSelect<KNRWTAXQueries, Where<KNRWTAXQueries.nonStockItemID, Equal<Required<APTran.inventoryID>>>>.Select(Base, doc.NonStockItemID))
{
foreach (KNRWTAXResponse response in PXSelect<KNRWTAXResponse, Where<KNRWTAXResponse.tAXQueID, Equal<Required<KNRWTAXResponse.tAXQueID>>>>.
Select(Base, queries.Taxqueid))
{
Responsevalues.Add(response.Response);
ResponseLables.Add(response.Response);
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 255, true, typeof(KNRWTAXQueries.response).Name, false, 1, string.Empty, Responsevalues.ToArray(),
ResponseLables.ToArray(), true, null);
}
}
}
}
// ((PXStringState)e.ReturnState).MultiSelect = false;
}
You can use RowSelected event of the row to set the list. No need to use FieldSelecting (however you can use field selecting too)
You should use PXStringListAttribute.SetList method to set new list instead of using string state
You should set MatrixMode=true in the aspx grid row so that list is recreated for each row (oterwise the list will be the same for all rows)
<px:PXGridColumn DataField="OrigTranType" Type="DropDownList" MatrixMode="true" />

Modify filtered data grid when a row is selected

I have a processing page which may contain multiple rows with a common id value. When a row is selected, I would like to deselect and disable all other rows with the same id value. Likewise if that row is deselected I want to re-enable all the other rows with the same id. I know I need to use a rowupdated event but I don't know how to attach to the cache for the grid. Any help is appreciated.
public void EDIOrder_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
EDIOrder row = (EDIOrder)e.Row;
if (row != null)
{
// attach to cache and update other rows with same id
}
}
I had a similar situation, where PayoutDetail records belonging to the same Payout needed to stay in synch. I chose Field_Updated for the event handling to select or deselect like-records:
protected virtual void RCPayoutDetail_Selected_FieldUpdated(
PX.Data.PXCache cache, PX.Data.PXFieldUpdatedEventArgs e)
{
RCPayoutDetail row = (RCPayoutDetail)e.Row;
if (row != null)
{
// keep all Payouts in synch
foreach (RCPayoutDetail rec in this.Records.Select())
{
if (rec.RCPayoutID == row.RCPayoutID &&
row.RCPayoutDetailID != rec.RCPayoutDetailID)
{
cache.SetValue<RCPayoutDetail.selected>(rec, row.Selected);
}
}
this.Records.View.RequestRefresh();
}
}
In your case for enable/disable, try adding:
PXUIFieldAttribute.SetEnabled<RCPayoutDetail.selected>(
cache, rec, !(bool)row.Selected);
// optional, see RowSelected comments and changes suggested below
cache.SetStatus(rec, row.Selected == true ?
PXEntryStatus.Notchanged : PXEntryStatus.Modified);
In a processing page, if you are disabling the entire row, but only enabling the Selected field during RowSelected, then add the following "if" line to RowSelected for interplay with row's Status:
protected virtual void RCPayoutDetail_RowSelected(PX.Data.PXCache cache, PX.Data.PXRowSelectedEventArgs e)
{
RCPayoutDetail row = (RCPayoutDetail)e.Row;
if (row != null)
{
//Set Row Enabled = false
PXUIFieldAttribute.SetEnabled(cache, e.Row, false);
// optional if line, otherwise always enable Selected
if(cache.GetStatus(row) == PXEntryStatus.Updated || row.Selected == null)
PXUIFieldAttribute.SetEnabled<RCPayoutDetail.selected>(
cache, row, true);
}
}

How to set First Dropdown value as default for first line in grid then Second value defaults from second line in grid

In the Product drop-down, there are 2 values, First value (Product) will default for first line only and Second value (Co-Product) will default from the second line.
I tried this in FieldDefaulting event
protected void TSFormulaProdsNCoProds_Product_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (TSFormulaProdsNCoProds)e.Row;
if (row == null)
return;
if (TSFormProdsNCoProds.Select().Count == 0)
{
e.NewValue = "P";
}
else
{
e.NewValue = "C";
}
}
Can anyone provide a suggestion to me?
Most likely you have PXDefault attribute decorated at DAC level. In that case, you need to set Cancel flag to prevent execution of FieldDefaulting event handlers that are defined in attributes.
Example :-
protected void TSFormulaProdsNCoProds_Product_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (TSFormulaProdsNCoProds)e.Row;
if (row == null)
return;
e.NewValue = (TSFormProdsNCoProds.Select().Count == 0) ? "P" : "C";
e.Cancel = true;
}
This is explained in Example 5.2: Inserting a Default Detail Data Record of T200 Acumatica Framework Fundamental course.

FGetting a Form Field from a grid extension

I have added a field to the Prepare Replenishment form that needs to be updated when a user selects a row in the Replenishment Item grid. How do I access the field. I know it is in the INReplenishmentFilterExt but I can't figure out how to get access to the extension.
Edit #1: I am able to get the value of the field but it does not update on the screen when I use cache.SetValue. I am trying to update this filter extension field from inside of the Selected event handler.
protected void INReplenishmentItem_Selected_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
{
var row = (INReplenishmentItem)e.Row;
if (row == null)
return;
INReplenishmentFilter filter = Base.Filter.Current;
INReplenishmentFilterExt filterExt = PXCache<INReplenishmentFilter>.GetExtension<INReplenishmentFilterExt>(filter);
decimal poAmount = filterExt.UsrPOAmount.HasValue ? filterExt.UsrPOAmount.Value : 0;
decimal lastPrice = pvi.LastPrice.HasValue ? pvi.LastPrice.Value : 0;
decimal newPOAmount = poAmount + lastPrice;
cache.SetValue<INReplenishmentFilterExt.usrPOAmount>(filterExt, newPOAmount);
}
You cannot set the value of the Filter using the Cache of INReplenishmentItem.
I have edited my answer, the code below should work.
//Always use virtual methods for Event Handlers
protected virtual void INReplenishmentItem_Selected_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
//Try not to use vars. Especially when you know the Type of the object
INReplenishmentItem row = e.Row as INReplenishmentItem;
if (row != null)
{
INReplenishmentFilter filter = Base.Filter.Current;
INReplenishmentFilterExt filterExt = PXCache<INReplenishmentFilter>.GetExtension<INReplenishmentFilterExt>(filter);
decimal poAmount = filterExt.UsrPOAmount ?? 0;
decimal lastPrice = pvi.LastPrice ?? 0;//Not sure what pvi is
decimal newPOAmount = poAmount + lastPrice;
//"sender" is the cache that specifically stores the datatype of row
//Therefor you cannot use it to update records of a different datatype
//You also should not pass an Extension into the argument that should be the row object you are trying to update
Base.Filter.Cache.SetValueExt<INReplenishmentFilterExt.usrPOAmount>(filter, newPOAmount);
}
}

Resources