How can I get the number of rows of a detail grid? - acumatica

I'm trying to get the number of rows in documents Details grid. I don't know how to call this inside of another instance.
for example: In this method I receive row by row, I want to know how can I get the total number of rows received.
public virtual void ARTran_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
var row = (ARTran)e.Row;
}
This is for screen Invoices and Meme (AR301000)

Do a .Select() of your data view and use the Count property.
var rowCount = Base.Transactions.Select().Count;
In your case, you want the data view used by the detail grid, which is Transactions. You can find more info on how the screen in builded by using the Inspect Element tool. You can read more about it on http://acumaticaopenuniversity.com/pdf/T300_Acumatica_Cust_Platform.pdf

Related

In acumatica, how can I make changes in the Cost tab show up in the Revenue tab?

For example, if I change the "Original Budgeted Quantity" field to 9.00 (see first image below), I would like that to also change in the Revenue tab (see second image) without having to change the same thing twice.
Is there a way I can achieve this?
Cost Tab
Revenue Tab
Here are the details of the two fields I have highlighted in the images above:
Cost Tab Field
Revenue Tab Field
Let me know if I need to clarify anything or provide more information :)
Unfortunately I'm not very familiar with the Project Entry screen, and after a quick glance I couldn't find an easy way to tie the records from the Cost Budget tab to the Revenue Budget tab.
If you are planning on tying these two records together you may need some additional customization work to create the link that you are looking for if it doesn't already exist.
As far as the update itself, that is pretty straightforward and can be accomplished with a simple event handler, as demonstrated below.
namespace MyCompany.MyCustomization
{
public class ProjectEntryExtMyCustomization : PXGraphExtension<ProjectEntry>
{
public static bool IsActive() => true;
#region Actions
#endregion
#region Events
protected virtual void _(Events.FieldUpdated<PMCostBudget, PMCostBudget.qty> eventHandler)
{
PMCostBudget row = eventHandler.Row;
if (row is null) return;
// Replace the stub below with your PMRevenueBudget lookup
// using the link that you have defined.
PMRevenueBudget revenueDetail = new PMRevenueBudget();
// Assigns the PMRevenueBudget Qty field to match the PMCostBudget new value.
revenueDetail.Qty = eventHandler.NewValue as decimal?;
// Updates the PMRevenueBudget record in the cache.
Base.RevenueBudget.Update(revenueDetail);
}
#endregion
}
}
Don't forget to replace the line where I create a new PMRevenueBudget with the logic that you need for looking up the linked PMRevenueBudget record that you need. Let me know if you have any questions.

How to add a column to the grid that shows value from another screen in Acumatica?

I'm new to Acumatica, could you please help me? I have too screens IN202500 (stock items) and SO301000(sales orders). I added a field to stock items and now I need to show a value from that field in grid column of sale orders for each stock items. I suppose that I need to use PXDefault attribute for this?
There are a number of ways you can do this. I'll provide 3 possibilities.
If your View used by the grid contains InventoryItem, you may be able simply to select your custom field from InventoryItem and add it directly to the screen. I'll assume this is not an option or you likely would have found it already.
Create a custom field in a DAC extension on SOLine where you add your custom field as unbound (PXString, not PXDBString) and then use PXDBScalar or PXFormula to populate it. I haven't used PXDBScalar or PXFormula to retrieve a value from a DAC Extension, so I'll leave it to you to research. I do know this is super easy if you were pulling a value directly from InventoryItem, so worth doing the research.
Create as an unbound field as in #2, but populate it in the SOLine_RowSelecting event. This is similar to JvD's suggestion, but I'd go with RowSelecting because it is the point where the cache data is being built. RowSelected should be reserved, in general, for controlling the UI experience once the record is already in the cache. Keep in mind that this will require using a new PXConnectionScope, as Acuminator will advise and help you add. (Shown in example.) In a pinch, this is how I would do it if I don't have time to sort out the generally simpler solution provided as option 2.
Code for Option 3:
#region SOLine_RowSelecting
protected virtual void _(Events.RowSelecting<SOLine> e)
{
SOLine row = (SOLine)e.Row;
if (row == null)
{
return;
}
using (new PXConnectionScope())
{
SOLineExt rowExt = row.GetExtension<SOLineExt>();
InventoryItem item = SelectFrom<InventoryItem>
.Where<InventoryItem.inventoryID.IsEqual<#P.AsInt>>
.View.Select(Base, row.InventoryID);
InventoryItemExt itemExt = item.GetExtension<InventoryItemExt>();
rowExt.UsrSSMyDatAField = itemExt.UsrSSMyDataField;
}
}
#endregion

how to hide templatefield dynamically using c#

I have a Grid View now i want to hide one column using C#.
Code:
protected void gvLadleCleaning_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[9].Visible = false;
}
Exception:
Index was out of range. Must be non-negative and less than the size of
the collection.
But currently my Grid View has 17 column.
Kindly help me to solve this problem.

How to cancel BeforeEdit event in gxt EditorGrid based on data stored in model for the selected row

I have an EditorGrid. I would like to cancel the edit (using the BeforeEdit event) if the user does not have edit rights to that specific column. This data (a "canEdit" value), is in the data store for the row, but has not been added a column to the grid.
I think the best way to go about this is by cancelling the edit in the BeforeEdit event. I am having trouble, however, getting the data from the selected row in the BeforeEdit event. If someone could point me in the right direction with a small code snippet for how to grab data values from the selected row in a BeforeEdit event, I would be most appreciative! Or, if there is a better way to proceed, would love to hear from you.
Thank you!
Jennifer
final EditorGrid<Plant> grid = new EditorGrid<Plant>(store, cm);
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<Plant>>(){
#Override
public void handleEvent(GridEvent<Plant> be) {
//This retrieves the model being edited.
Plant model = be.getModel();
GWT.log("Model edited "+model.getName());
}
});
This snippet uses the sample program provided by GXT. You can see the demo of the original sample as well the full code here.
Here's what I used that worked:
grid.addListener(Events.BeforeEdit, new Listener<BaseEvent>() {
#Override
ModelData comment = ((EditorGrid)be.GetSource().getSelectionModel().getSelectedItem();
Boolean canEdit = Boolean.parseBoolean(comment.get("canEdit").toString());
be.setCancelled(!canEdit);
}

How can I customize SharePoint list column aggregation (total) calculations?

I have a SharePoint list column of type 'Single line of text'. Out of the box SharePoint only provides the ability to display a 'Count' total for this column type. I would like to be able to perform a custom aggregation on the data (specifically to sum numeric data held as text to overcome this deficiency).
I have found examples for doing something similar for calculated columns using XSLT and Javascript but I believe that both of these approaches fail where the data is paginated (only aggregating the subset of the list content displayed on screen).
I want to retain the functionality of the ListViewWebPart (rendering, sorting, filtering, view definition, action menus etc.) but add this functionality. How can I do this?
The only things you can do with totals are:
Average; Count; Max; Min; Sum; Standard Deviation; Variance
Not sure how to calculate anything else.
I've not had a chance to fully test it but this is the best I could come up with:
Create a WebPart which contains two controls:
A ViewToolBar with the context of the list/view to be displayed
A Literal containing the rendered HTML of the view to be displayed
This will then render as the original list/view.
On rendering the WebPart, get the items from the view, specifying the RowLimit as the maximum value so that all items in are retrieved (not just the first page).
Iterate over the items, calculating the total in a suitable data type to retain precision.
Render the total as a hidden value in the HTML and overwrite the rendered Count total with Javascript such as by the method described here.
A rough sketch of the code:
public sealed class TextAggregatingWebPart : WebPart {
protected override void CreateChildControls() {
base.CreateChildControls();
var web = SPContext.Current.Web;
var list = web.Lists[SourceList];
var view = list.Views[ViewOfSourceList];
var toolbar = new ViewToolBar();
var context = SPContext.GetContext(
Context, view.ID, list.ID, SPContext.Current.Web);
toolbar.RenderContext = context;
Controls.Add(toolbar);
var viewHtml = new Literal {Text = view.RenderAsHtml()};
Controls.Add(viewHtml);
}
protected override void Render(HtmlTextWriter writer) {
EnsureChildControls();
base.Render(writer);
var web = SPContext.Current.Web;
var list = web.Lists[SourceList];
var view = list.Views[ViewOfSourceList];
var items = list.GetItems(new SPQuery(view) {RowLimit = uint.MaxValue});
foreach (SPItem item in items) {
// Calculate total
}
// Render total and Javascript to replace Count
}
}
Note that this doesn't solve the problem with the Modify View screen only showing Count as a total for text columns. Also there is a possibility that changes to the list between the initial rendering by the view and the retrieval of the items for aggregation could produce discrepancies between the total and the displayed items.

Resources