How to 'Add / Sum / Total / Calculate' dynamic tables in google app maker - google-app-maker

It's probably the simplest thing in the world but I can't seem to add/sum/calculate tables in App Maker. I have attached an image of the App preview. I will try to keep this simple. The page has 3 data sources as follows:
Apex_customer_po - This is where our employee's input customer purchase orders including the PO number (string), the overall value of the PO (number), and the details (string)
Apex_customer_po_wo_details - Purchase orders are often broken up by our customer in to multiple work orders (WO), a task break down each with it's own values including Date (date), WO number (string), WO amount (number), details (string)
Apex_customer_po_wo_costing - This is where we keep track of what work we've done and how much of each work order's money we've used. The fields include a reference number(string), parts price (number), Part details (string), Labour hrs (number), Labour rate (number), Total labour (number), and Invoice total (number), Overall total of all invoices for the work order (number)
My data relations are as follows:
Apex_customer_po
Apex_customer_po_wo_details (One Apex_customer_po to Many Apex_customer_po_wo_details)
Apex_customer_po_wo_costing (One Apex_customer_po_wo_details to Many Apex_customer_po_wo_costing)
Shows the general configuration of the PO app preview mode. I includes 2 work orders each with their associated invoices
Shows the general configuration of the Layout view of the app page
I have figured out how to calculate the cost of my labour:
#datasource.item.Labour_total = #datasource.item.Labour_time * #datasource.item.Labour_rate
I have figured out how to calculate the total of each invoice:
#datasource.item.Invoice_total = #datasource.item.Parts_amount + (#datasource.item.Labour_time * #datasource.item.Labour_rate)
But I can't for the life of me figure out how to 'Add / Sum / Total / Calculate' the individual invoices from each Work Order to get a total value.
I've tried unsuccessfully to use reduce and a bunch of other methods, but I can't ever seem to get the syntax correct even on basic 1+1 type calculations. I don't have much experience in app maker but I've been doing fine and loving it... until now.
Update 001:
I have managed to get a reduce function to perform a simple table addition for me based off the following blog post. blog.supportgroup.com/google-app-maker-cold-calculations - And the ball is rolling again. Now I need to rework how my data sources are set-up changing the numbers to strings –
Update 002:
I managed to get the reduce function to work in my app. However it totals the values from the selected cells across the data source. For example I have a PO, lets call it PO#1 and there are 5 items that total $5. When I start a new PO#2, it carries over the total of PO#1. So it calculates the entire data source regardless of the fact that it's 2 different PO#'s and I don't know how to make it stop. The code I have used is as follows
#datasource.item.Total = getFormatMoney((#datasources.Apex_customer_po_wo_costing.items).reduce((b,a) => Number(a.Parts_amount) + (Number(a.Labour_rate) * Number(a.Labour_time))+ Number(b) , 0 ),2,",",".")
The getFormatMoney(),2,",",".") is a client side java script that formats the currency
Thanks in advance for the assistance.
UPDATE 003:
I am now trying to do this in a different way with a calculated Data source and I am following this tutorial:
YouTube 7.33min long - Totals in Drive Tables tutorial
I have re-created the app step by step but I am getting the following error regarding my SQL query code:
E Mon Nov 18 13:38:49 GMT-700 2019 Exception: Malformed SQL. More
information: Error with SQL statement: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near var totals = (wholesale:0, retail:0, profit:0); var records = app.models.autos. at line 1.
E Mon Nov 18 13:38:49 GMT-700 2019 Executing query for datasource
totals: (Error) : Malformed SQL. More information: Error with SQL
statement: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near var totals = (wholesale:0, retail:0, profit:0); var records =
app.models.autos. at line 1.
E Mon Nov 18 13:38:49 GMT-700 2019 Executing query for datasource
totals failed.
My code in my data source is as follows:
var totals = {wholesale:0, retail:0, profit:0};
var records = app.models.autos.newQuery().run();
records.forEach(function( item ){
totals.wholesale += item.wholesale;
totals.retail += item.retail;
totals.profit += (item.retail - item.wholesale);
});
var record = app.models.totals.newRecord();
record.wholesale = totals.wholesale;
record.retail = totals.retail;
record.profit = totals.profit;
return [record];
Anyone have any thoughts on what the mistake is?
Update 004
Success - The data source type needed to be a "Calculated" type not a "Calculated SQL". Now I am going to see if I can apply this new type of calculation to my existing problem.

It seems like the way to go on this is the calculated model route the tutorial I linked in Update 003 is a solid path to go down.

Related

AX .NET PricingEngine class - Cannot get Sales Transaction data, line data is ok

I have recently found an interesting article about using .NET Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine to calculate the price and discount for an order: (https://community.dynamics.com/365/financeandoperations/b/kurthatlevik/posts/dax2012-r3-playing-with-retail-crt)
I modified the author's code by adding these two lines at the end of the job to get the total amount and the total number of items of the order (off course, I already changed my ItemId and InventDimId to values which are suitable with my AX 2012 R3 system):
Price = crtSalesTransaction.get_TotalAmount();
qty = crtSalesTransaction.get_NumberOfItems();
All I received are 0s.
I tried to check the MS document about the class, but the information there is quite limited (https://learn.microsoft.com/en-us/dynamicsax-2012/appuser-itpro/pricingengine-methods-microsoft-dynamics-commerce-runtime-services-pricingengine). I also tried all other related methods of the class Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction, but no luck. So I'm quite confused. Does the code need something more or is it a bug of AX? Could someone give me a hint?
Thank you.

How do I create a running count of outcomes sequentially by date and unique to a specific person/ID?

I have a list of unique customers who have made transactions over a year (Jan – Dec). They have bought products using 3 different methods (card, cash, check). My goal is to build a multi-classification model to predict the method pf payment.
To do this I am engineering some Recency and Frequency features into my training data, but am having trouble with the following frequency count because the only way I know how to do it is in Excel using the Countifs and SUMIFs functions, which are inhibitingly slow. If someone can help and/or suggest another solution, it would be very much appreciated:
So I have a data set with 3 columns (Customer ID, Purchase Date, and Payment Type) that is sorted by Purchase Date then Customer ID. How do I then get a prior frequency count of payment type by date that does not include the count of the current row transaction or any future transactions that are > the Purchase Date. So basically I want to do a running count of each payment option, based on a unique Customer ID, and a date range that is < purchase date of that training row. In my head I see it as “crawling” backwards through the transactions and counting. Simplified screenshot of data frame is below with the 3 prior count columns I am looking to generate programmatically.
Screenshot
This gives you the answer as a list of CustomerID, PurchaseDate, PaymentMethod and prior counts
SELECT CustomerID, PurchaseDate, PaymentMethod,
(
select count(CustomerID) from History T
where
T.CustomerID=History.CustomerID
and T.PaymentMethod=History.PaymentMethod
and T.PurchaseDate<History.PurchaseDate
)
AS PriorCount
FROM History;
You can save this query and use it as the source for a crosstab query to get the columnar format you want
Some notes:
I assumed "History" as the source table name - you can change the query above to use the correct source
To use this as a query, open a new query in design view. Close the window that asks what tables the query is to be built on. Open the SQL view of the query design - like design view, but it shows the SQL instead of the normal design interface. Copy the above into the SQL view.
You should now be able to switch to datasheet view and see the results
When the query is working to your satisfaction, save it with any appropriate name
Open a new query in design view
When you get the list of tables to include, switch to the list of queries and include the query you just saved
Change the query type to crosstab and update the query as needed to select rows, columns and values - look up "access crosstab queries" if you need more help.
Another tip to see what is happening here:
You can take the subquery - the parts inside the () above - and make
just that statement into it's own query, excluding the opening and closing (). Then you can look at it's design view to see what it does
Save it with an appropriate name and put it into the query above in place of the statement in () - then you can look at the design view.
Sometimes it's easier to visualize and learn from 2 queries strung together this way than to work with sub queries.

ODBC Microsoft Query BMC Remedy SLM Status Table

I want to use Microsoft Query to pull out stats on incident SLA status that can normally be seen in the SLM Status window. See the pictures below for reference.
However, I am struggling with finding the proper table to get the data from. What table is available to use as a ODBC data source for getting this information?
[
The data you are looking for is stored in the SLM:Measurement form. You'll want the following fields:
SVTTitle (SVT Title) (300411500)
GoalCategoryChar (Incident Response Time) (300426800)
GoalTimeHr (Hours) (300396000)
GoalTimeMin (Min) (300451200)
GoalSchedCost (Cost Per Min) (301489500)
SVTDueDate (Due Date/Time) (300364900)
MeasurementStatus (Progress) (300365100)
ApplicationUserFriendlyID (Incident ID) (301238500)
From what I can tell, the "Next Target Date:" is calculated by Remedy when the SLM dialog is opened using the active links:
SLM:IntegrationDialog:OnLoadSelectTimeBasedTab_SetNextDueDate-Incident
SLM:IntegrationDialog:OnLoadSelectTimeBasedTab_SetNextDueDate-Change
SLM:IntegrationDialog:OnLoadSelectTimeBasedTab_SetNextDueDate-Request
It isn't stored in the table.
Hope this helps!

Cloudkitty - Rating display issue

In my Devstack setup there was a issue in displaying details in the Rating section.
Pricing was configured correctly, During Instance creation Rate is displayed in the instance creation window.
But after creation of instance I am checking the Rating section for rates or cost.
It was not displaying the value as needed.
I checked the DB table (rated_data_frames) in Cloudkitty.
It doesn't have the necessary values immediately.
I was continuously checking for some hours consecutively.
But I can be able to see that Cloudkitty DB is getting updated with the values after some hours from instance creation.
That is after some hours, it is getting added in table regarding the Instance created.
So that in Front-end also it got displayed.
I want to know why it is happening.
Is there any solution for the same to get the results immediately.
Simply I need to get the results immediately in rating section.
I can be able to see that in cloudkitty.conf file section is there as follows:
# Rating period in seconds. (integer value)
#period = 3600
#wait_periods = 2
If changing this will help us.?

Iteration over VendTransOpen

This happens in Accounts Payable -> Journals -> Payments -> Payment Journal.
I choose to see the Lines for a journal and from Functions I select Settlement. I am not sure if this is the same for everyone else.
So, when clicking Settlement, VendOpenTrans opens. I need to iterate over it, and Mark the records according to the invoice of the previously selected LedgerJournalTrans field.
First of all I have to check the VendOpenTrans fields which I am not able to accomplish.
I have added the following piece of code in the init of VendTransOpen:
VendTrans vt;
vt = vendTransOpen_ds.getFirst(true) as VendTrans ;
while (vt)
{
//Do your thing
vt= vendTransOpen_ds.getNext() as VendTrans ;
}
No elements seem to be present in the vendTransOpen_ds..
Can someone give me a hint about this?
Update 1:
Found this :
Understanding the Settlement Mechanism in Microsoft Dynamics AX
and
Automatic mark a Settlement Transactions on a Payment Journal in AX 2012
I didn't think it would be so damn difficult.. I will start digging tomorrow.
Several things are wrong, but probably my #2 is your main problem.
If you place this code in the init method, the query hasn't been executed yet, so nothing will be there. See https://msdn.microsoft.com/en-us/library/aa608211.aspx
Your code will never enter while (vt) because vt will never have a value as written because VendTrans and VendTransOpen are two different tables that don't support inheritance.
The only reason vt = vendTransOpen_ds.getFirst(true) as VendTrans ; doesn't throw an error is because FormDataSource.getFirst()/getNext() returns a Common table record.
What Jan said too.
First off, use getFirst(0) before using getNext().
The zero indicates you want all records rather than marked.
Search, use cross reference tool, or google to get lots of references for the use of these functions.

Resources