Hi @Joaquin_Carminio - I don’t have an existing sample laying around, but here’s something I cooked up quickly:
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.addNetworkDomain("example.com");
pack.addFormula({
name: "StartJob",
description: "Starts a job, and returns an ID to track it.",
parameters: [
// TODO: Add parameters.
],
resultType: coda.ValueType.String,
isAction: true,
execute: async function (args, context) {
// TODO: Make a request to start the job, and return the job ID.
// Returning a random ID in this example.
let jobId = Math.random().toString(36).substring(2);
return jobId;
},
});
pack.addFormula({
name: "CheckJob",
description: "Checks if the job is complete.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "jobId",
description: "The ID of the job.",
}),
],
resultType: coda.ValueType.String,
isAction: true,
execute: async function (args, context) {
let [jobId] = args;
// TODO: Make a request to check if the job is finished.
// Flipping a coin in this example.
let isComplete = Math.random() > 0.5;
let result;
if (isComplete) {
// TODO: Collect the result of the job.
result = {
message: "Hello world!",
status: "complete",
};
} else {
// Generate a value indicating that it's pending.
result = {
status: "pending"
};
}
// Return the result as JSON.
return JSON.stringify(result);
},
});
// Define a schema for the result object.
const ResultSchema = coda.makeObjectSchema({
properties: {
status: { type: coda.ValueType.String },
message: { type: coda.ValueType.String },
},
displayProperty: "status",
});
pack.addFormula({
name: "FormatResult",
description: "Formats a result.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "resultJSON",
description: "The JSON of the result.",
}),
],
resultType: coda.ValueType.Object,
schema: ResultSchema,
execute: async function (args, context) {
let [resultJSON] = args;
// Just parse the SON and return the object.
return JSON.parse(resultJSON);
},
});
pack.addColumnFormat({
name: "FormatResult",
instructions: "Formats a result.",
formulaName: "FormatResult",
});
You would then setup a table with:
- The “Start Job” button that outputs to a “Job ID” column.
- A “Check Job” button, that takes the Job ID value as input, and writes to a “Results” column.
- The “Format Result” column format applied to the “Results” column.
You would push the first button to kick off the job. Then you would press the “Check Job” button to see if it’s complete and if so get the results. The results would be formatted using the column format so that you can use the Coda formula language to access the different fields.
Let me know if that helps!