Create a simple setup and a run script for a connector
For demonstration purposes, the following content will cover the case of using a table as a data source. Similar for the external API case.
Procedure
Set up the setup script
The Adaptive Framework Setup Script is responsible for returning a field catalog describing the available data to be used within the Adaptive report.
Code for the Setup script:
let fieldCatalog = [];
fieldCatalog.push({ name: "name", label: "Name", type: "text",usage:"OUTPUT"}); // name will appear only under Output
fieldCatalog.push({ name: "part_number", label: "Part number", type: "text" });
fieldCatalog.push({ name: "checkup_date", label: "Checkup date", type: "text" });
fieldCatalog.push({ name: "assigned_for_checking", label: "Assigned status", type: "boolean" });
result.data = fieldCatalog; // passing the possible components back to the adaptive app
complete();
-
Each object in the array will be displayed in the component tree. For the Setup script to work, name, label and type must be included in the objects. You may also add usage as a key in the objects.
-
The key usage is a non-mandatory field that determines whether a field is available for INPUT, OUTPUT or BOTH. For example, is OUTPUT will only display the component under Output in the Adaptive Designer.
-
The key type
For more information, view adaptive in the code snippets.
Set up the run script
The run script is responsible for processing any request made by the Adaptive Framework Application and passing it back the application. To prepare the data you will pass back to your adaptive application, you will need a data source.You may select either a specific table or an external API by dropping it in the Run script.
Code for the Run script:
// In this case, "equipment" is the name of the table used in the example and our
const runData = [];
// Fetching all data from the table
const entity = await entities.equipment.createQueryBuilder("alias")
.getMany();
for (const i = 0; i < entity.length; i++) {
equip_name = entity[i].name;
part_number = entity[i].part_number;
checkup_date = entity[i].checkup_date;
assigned_for_checking = entity[i].assigned_for_checking;
// each key name must match with the value of the key "name" from each object in the "fieldCatalog" array
runData.push({
"name": equip_name,
"part_number": part_number,
"checkup_date": checkup_date,
"assigned_for_checking": assigned_for_checking
});
}
result.data = runData; // passing data back to the adaptive app
complete();
Result
You successfully created a simple Setup and a Run script for a Connector. The outcome of these scripts will reflect on the component tree.