GroupBy aggregate with record count in projection DAC - acumatica

I'm currently working on a processing screen that should be showing a listing of custom orders from my DAC summarized by orderid.
The table itself stores a full listing of the order line items.
For example:
OrderNbr, OrderDate, LineNbr, Desc, InvtId, Qty, ExtPrice, isValidated
The grid of the processing screen should show the following information
OrderNbr, OrderDate, Desc, Count(LineNbr), Sum(ExtPrice)
I've created a projection DAC to group the lines by OrderNbr/OrderDate
[PXProjection(typeof(Select4<CWOrderTable,
Where<CWOrderTable.isValidated,Equal<boolTrue>>,
Aggregate<
GroupBy<CWOrderTable.orderNbr,
GroupBy<CWOrderTable.isValidated,
Sum<CWOrderTable.ExtPrice>>>>>
public partial class CWOrderSummary : IBqlTable
What I'm not able to get is a count of the line items that composes this order. I attempted to add a Count<> aggregate to the above however that doesn't return an actual count, simply the MAX() of the field. I couldn't find a great example of using Count() in a projection DAC.
I also found the article on the asiablog regarding the ScalarCount function and attempted that.
article here: http://asiablog.acumatica.com/2016/05/scalarcount-bql-operator.html
There are no errors using this however the subquery never is executed/passed to SQL and the value is always null.
Anyone have any recommendations or examples on how to get the count of records this way?
This is using Acumatica 6.10.0010. I'm partially wondering if it's a build issue and we need to force the customer to upgrade.
Thanks

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.

OrderBy in PXProjection Select does not work

Have any of you experienced this issue in Acumatica?
Adding OrderBy to Select2 in PXProjection attribute has no effect.
I checked the SQL query in Request Profiler and the data is sorted by key fields of the DAC.
Try adding your OrderBy to the PXSelect which is using the DAC made with the PXProjection. Note that by default, the records are ordered by the DAC keys.
In almost every case Acumatica will sort by the key fields first, so if your expectation was to have the data sorted exactly as in your OrderBy<> criteria then this won't work. What you can do instead of override the order directly in the view delegate, like this:
PXView select = new PXView(Base, true, this.myView.View.BqlSelect);
select.OrderByNew<OrderBy<Desc<MyDac.myField1, Desc<MyDac.myField2>>>>();
//<rest logic to select from the view>
This will always replace the order with your custom sort order. If you only want to do it only when the user hasn't altered the sort order in a grid, you can add a condition like that:
if (PXView.SortColumns.Length == this.myView.Cache.Keys.Length)
{
// apply custom default sort order
select.OrderByNew<OrderBy<Desc<MyDac.myField1, Desc<MyDac.myField2>>>>();
}

Maximo: show last status memo for current work order

In Maximo, I want to retrieve the most recent status memo and add the WOSTATUS.MEMO field to Work Order Tracking Module via Application Designer. In the Work Order Tracking application, to see the same information, you'd go to an individual Work Order > Select Action > View > Work Order History.
You may have noticed the WOSTATUS relationship on the WORKORDER object and found that you can't control which of the many WOSTATUS records for this work order gets chosen for showing the memo. You'll need to make a copy of this relationship which specifically finds the latest record. To find that latest record, you could go for the WOSTATUS record with the CHANGEDATE matching the STATUSDATE on the work order or with the highest WOSTATUSID. Assuming you go for the former, because it doesn't require a subquery, you'll create a new relationship from WORKORDER to WOSTATUS called LASTSTATUS with a where clause like this:
wonum = :wonum and siteid = :siteid
and status = :status and changedate = :statusdate
You can then use the standard Relationship.Attribute syntax for the Attribute property of a Textbox in App Designer: LASTSTATUS.MEMO.
In case you were interested, here's the where clause you would use if you wanted to go for the WOSTATUSID instead:
wonum = :wonum and siteid = :siteid
and wostatusid = (
select max(wostatusid)
from wostatus
where wonum = :wonum and siteid = :siteid
)
(Some may argue the toss about whether the first line in the above query is needed. I would respond with the suggestion to test for performance / optimal execution plan in your database environment.)
I hope that helps.

ordering records by time

I created a simple view to return the blog title and time
function(doc) {
if ( doc.TITLE) emit(doc.TIME, doc.TITLE);
}
what is a simple way to display newest blog articles first (by default it is the other way around)?
Just apply descending sort order at view request e.g.
GET /dbname/_design/titles/_view/by_time?descending=True
And view output would be sorted in reversed way - newest blog articles will go first. Remember that startkey/endkey parameters will limit key range for this reversed order. More about view query parameters you could found in CouchDB wiki

SharePoint returns extra system columns

I do query to SherePoint. I have created query, viewquery and query options.
Web services returns me great results, but it include some other system columns such as:
ows_Modified , ows_DocIcon, ows_Editor. I don't want them. How do I return only those which is in ViewQuery string?
My queryoptions is:
#"<QueryOptions>
<IncludeMandatoryColumns>False</IncludeMandatoryColumns><ViewAttributes Scope='Recursive' />
</QueryOptions>";
Thanks!
In order to return only selected columns (and not all of them) use ViewFields property of SPQuery object. You can find some more information about it and a sample code here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx.
In order to do it from javascript, you can try code as written here (that post is on another topic, but it still shows how to specify fields to select): https://sharepoint.stackexchange.com/questions/33683/spservices-today-not-returning-correct-results.

Resources