问题
Basically I have two datasets:
Dataset 1 - records the details of a store visit. Merchandiser name, location, date & a relation to SKU (Dataset2) Dataset 2- This is the SKU data, where the stock levels for each sku are input as a new record, each associated to a visit from dataset 1.
I have two issues:
I want to combine this data into a single table. I want to show each sku record, with additional columns for the visit information (such as the location & date). How do I do this.
How do I combine this data for use elsewhere, such as google data studio. Esentially I want to be able to see an SKU's stock-level's history, or the date it was last updated.
THanks
回答1:
You need to create Calculated Data Source. You can refer this sample.
On a high Level
- Add data source in Appmaker.
- Select Calculated, provide Name and Create the data source.
Once your Calculated Model is in place. Add fields as per need basis. e.g. If you want to store Sum of two fields, create one Integer field in Calculated Model. Here's how your calculated data model will look like.
Now go to Second Tab which is "Datasources". Click on the Data Model name there. You should see an option to write server side script.
Here you should write your logic for combining your data sources. I can provide you one sample to achieve this.
//server script
var calculatedModelRecords = [];
var recordsByStatus = {};
var allRecord = app.models.Request.newQuery().run(); //your existing data source.
for (var i = 0; i < allRecord.length; i++) {
var record = allRecord[i];
var draftRecord = app.models.TAT.newRecord(); //new data source
draftRecord.CreatedOn = record.CreatedOn;
draftRecord.DocumentName = record.DocumentName;
draftRecord.DueDate = record.DueDate;
draftRecord.DaysPerStage = record.DaysPerStage;
draftRecord.Status = record.Status;
calculatedModelRecords.push(draftRecord);
}
return calculatedModelRecords;
来源:https://stackoverflow.com/questions/51018281/combine-data-from-two-datasources-into-a-single-table