Combine data from two datasources into a single table

老子叫甜甜 提交于 2019-12-23 05:27:51

问题


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:

  1. 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.

  2. 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

  1. Add data source in Appmaker.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!