Toggle navigation
Home
▼ Details
Products and pricing
Chart gallery
User stories
Text analytics
CDC NAMCS Library
Blog
Tutorials
Contact
Sign in
Post Editor
← All help posts
View post
Save
We can [Combine data](/process-data/combine-data-using-a-simple-stack) using a simple process when all the data we need is housed within one project space. However, to combine data tables that are in separate projects or even non-Protobi sources we use an asynchronous data process. This is applicable when merging external data, and operating on results of other processes or data in other projects. ## Add an asynchronous data process In the Data tab under "Project settings..." create a data process and set it to "Asynchronous" rather than "Simple": <img src="/uploads/upload/image/5200/direct/1586065431423-1586065431423.png" alt="Protobi Project settings page for "car_sales.sav" showing Data table configuration for a process named "merge". The form displays: Name ("merge"), Type ("process"), Process type dropdown set to "Asynchronous", Updated ("Sat Apr 04, 2020 04:14 pm"), Filename ("simple.csv"), empty Description field, Data table section with "View data online" button, Admin section with "Edit/Run", "Delete", and "Make primary" buttons, Download section with "Original", "Direct", "CSV", "SAV" buttons, Layouts showing "SPSS syntax", and Docs showing "Wiki". The left sidebar shows "Data" highlighted in blue." style="text-align: center; width: 697px;" class="fr-fic fr-dii"> Click "Edit/Run" to edit the code view. ## Combine data from multiple projects This example code combines data from multiple Protobi projects. “var sources” is an array containing objects of key pairs. Next to “datasetId” is a unique identifier found in the project’s URL. Next to “key” is a name that will represent the project. Next to "tables" is the name of the data table you want to use from that project (if there's more than one separate). ``` var sources = [ {datasetId: "5dc40f3972a9af00046aceb3", key:"project1", tables:["main","main2"]}, {datasetId: "5db276c8445a1c000477aa07", key:"project2", tables:["main"]} ] async.mapSeries( sources, function(entry,cb) { Protobi.get_tables(entry.datasetId, entry.table, cb) }, function(err, tables) { if (err) { console.log("error message") return $.notify(err) } else { // datasets is now an array of results paralleling `sources` var project1 = tables[0] var project1 = tables[1] var project2 = tables[2] var rows = Protobi.stack_rows(tables) $.notify("Process complete", "success") console.log("rows",rows) return callback(null,rows) } }) ``` ## Combine results of a data process Using an asynchronous data process, you can also combine data tables with the result of data processes. In the example below, the code combines a data table from one project with the result of a data process from another. ``` var sources = [ {datasetId: "5dc40f3972a9af00046aceb3", key:"project1", table:"main"}, {datasetId: "5db276c8445a1c000477aa07", key:"project2", table:"process"} ] async.mapSeries( sources, function(entry, cb) { Protobi.get_table(entry.datasetId, entry.table, cb) }, function(err, tables) { if (err) return callback(err) else { // datasets is now an array of results paralleling `sources` var project1 = tables[0] var project2 = tables[1] console.log(tables) var rows = Protobi.stack_rows(tables) $.notify("Process complete", "success") return callback(null,rows) } } ) ``` ## Retrieve project setup configuration Asynchronous data processes can access not just data tables but can also get the elements configuration. Elements determine the setup and organization of a project, including question titles and value format. You can find the configuration for a project in [settings](/admin-access/project-settings) on the "Elements" tab. The code below calls the elements of a specified project. The following example does three things: - gets the elements configuration for this project, - gets the data from data table **main** from another project - returns that table as the data table for this process ``` Protobi.get_elements(function(err, tabular) { if (err) return callback(err) var q1 = tabular.getDimension('q1') Protobi.get_tables("5cf6a9ae9468bab783ebc277","main", function(err, rows) { if (err) return callback(err) console.log(rows) rows.forEach(function(row) { row.q1 = q1.getValue(row) // use the element q1 to calculate a value for row.q1 }) return callback(null, rows) }) }) ``` Here is an example of an asynchronous data process in context: <img src="/uploads/upload/image/5200/direct/1586065689880-1586065689880.png" alt="Protobi "Data process merge" interface showing JavaScript code editor with description "This process runs asynchronously. Explicitly call methods to get data and return 'callback(err, data)' when done." The code displays 14 lines including: Protobi.get_elements function with console.log(els), var q1 = els.getDimension('q1'), Protobi.get_tables with parameters for table ID "5cf6d9ae9468bdb783ebc277" and "main", error handling with if (err) return callback(err), console.log(rows), and return callback(null, rows). Green "Save" and gray "Run..." buttons appear at top." class="fr-fic fr-dii"> **Reminder**: For data processes, "Save" and "Run" the process after you are done editing the code view. To use the result of the process as the primary data for the project, you will need to set it as "Primary". *Data processes are specific to each project, and your code may not look identical to our example.* ## Advanced support Protobi can handle complex data processing cases, not limited to those that are documented within our tutorials. Our support team is ready to help you with your specific goals. Please contact us at [support@protobi.com](mailto://support@protobi.com) to discuss further.
Publishing
Date
Status
Published
Draft
Slug
edit
Content
Thumbnail
Categories
Manage
New to Protobi?
Charts
Making Changes
Intermediate topics for editors
Frequently Asked Questions
SERMO Topics
Tutorial Pages
Internal Docs
Data Processing
Videos
Obsolete
GSG Admin
SERMO Admin
GSG Topics
How to...
Basics for viewers
Basics for editors
For project admins
Advanced topics
Assessments
Articles (in-progress)
New and updated articles
Process data in Protobi
superseded
Text open-end questions
Troubleshooting
Tracking studies
Organizing the view
API References
Tools
AI Database
Checking AI...
Convert to MD
Danger zone
Delete