Function
Boltic Workflows supports the execution of custom JavaScript/Python code using the Function activity. This allows you to write complex logic and manipulate data within your workflows.
JavaScript
JavaScript is the main tool for data manipulation and transformation in Boltic Workflow. Use the Function activity to write custom JavaScript code that can transform data and execute complex logic. Additionally, you can integrate popular JavaScript libraries to further enhance the capabilities of your workflows.
Write and execute JavaScript code
You can create complex logic or manipulate data using JavaScript methods like map(). For example, you can use map() to transform an array of customer records:
const customers = API_1.result.customers;
return customers.map((customer) => ({
fullName: customer.name,
emailAddress: customer.email,
}));
Sample usage of axios
const req = {
url: "<your_url>",
data: {
a: 1,
},
headers: {
"x-data": 1,
},
};
const res = await axios.post(req.url, req.data, { headers: req.headers });
return res.data;
Sample usage of lodash
return _.defaults({ a: 1 }, { a: 3, b: 2 });
Sample usage of crypto
const hash = crypto.createHash("sha256").update("example").digest("hex");
return hash;
Sample usage of Buffer
const buffer = Buffer.from("Hello World", "utf-8");
return buffer.toString("base64");
Sample usage of querystring
const parsed = querystring.parse("name=boltic&status=active");
return parsed.name; // Output: "boltic"
Sample usage of url
const parsedUrl = url.parse("https://example.com/path?name=boltic");
return parsedUrl.query; // Output: "name=boltic"
Sample usage of FormData
const form = new FormData();
form.append("key", "value");
return form.getBuffer();
Sample usage of xlsx
const url = "<your_url>";
const response = await axios.get(url, {
responseType: "arraybuffer",
});
const workbook = xlsx.read(response.data, { type: "buffer" });
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const data = xlsx.utils.sheet_to_json(worksheet);
return data;
Sample usage of papaparse
const readCSV = async (url) => {
try {
const response = await axios.get(url, { responseType: "text" });
const parsed = papaparse.parse(response.data, {
header: true,
skipEmptyLines: true,
});
return parsed.data;
} catch (error) {
console.error("Failed to fetch or parse CSV:", error);
throw error;
}
};
const csvUrl = "<your_url>";
const v = await readCSV(csvUrl);
return v;
Sample usage of PDF Parser
async function convertPdfUrlToMarkdown(pdfUrl) {
try {
const response = await axios.get(pdfUrl, { responseType: "arraybuffer" });
const data = await pdfParse(response.data);
const markdown = data.text
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => `- ${line}`)
.join("\n\n");
return markdown;
} catch (error) {
console.error("❌ Error processing PDF:", error.message);
return error;
}
}
const pdfUrl = "<your_pdf_url>";
return convertPdfUrlToMarkdown(pdfUrl, "output.md");
Sample usage of Boltic SDK
const client = BolticSDK.createClient(BOLTIC_PAT);
console.log("✅ Boltic SDK installed successfully!");
// Example: Find table by its name
const tableName = "users";
const filteredTables = await client.tables.findAll({
where: { name: tableName },
});
return {
count: filteredTables.data.length,
users: filteredTables,
};
- Replace
BOLTIC_PATwith your Personal Access Token (get it from Settings → PAT Tokens). - The returned object flows to the next helper/activity like any other Function output.
Optional configuration example:
const client = BolticSDK.createClient(BOLTIC_PAT, {
region: "asia-south1",
timeout: 30000,
retryAttempts: 3,
retryDelay: 1000,
debug: false,
});
Sample usage of FDK Client JavaScript
FDK Client JavaScript provides two clients for interacting with the Fynd Platform:
ApplicationClient - For application-level operations:
const applicationClient = new fdk.ApplicationClient({
applicationID: FYND_APPLICATION_ID,
applicationToken: FYND_APPLICATION_TOKEN,
});
// Example: Fetch product details by slug
const product = await applicationClient.catalog.getProductDetailBySlug({
slug: "product-slug-here",
});
return {
productName: product.name,
productId: product.uid,
price: product.price,
};
PlatformClient - For platform-level operations:
const client = new fdk.PlatformClient({
companyId: FYND_COMPANY_ID,
apiKey: FYND_API_KEY,
apiSecret: FYND_API_SECRET,
domain: FYND_DOMAIN,
});
// Get access token
const token = await client.getAccesstokenObj({
grant_type: "client_credentials",
});
client.setToken(token);
// Example: Fetch tickets
const tickets = await client.lead.getTickets();
return {
ticketCount: tickets.items.length,
tickets: tickets.items,
};
- Replace environment variables with your actual Fynd Platform credentials.
- The returned object flows to the next helper/activity like any other Function output.
Accessing Data from Previous Activities
Data from previous activities can be accessed directly using the activity's name as a reference.
Example:
const customerData = API_1.result.customers;
return customerData.payload.map((customer) => customer.email);
Custom libraries supported:
-
axios
→ A promise-based HTTP client for making API requests and handling responses. -
lodash
→ A utility library providing modular functions for manipulating arrays, objects, and strings. -
crypto
→ A module for implementing cryptographic functionality such as hashing and encryption. -
Buffer
→ A global Node.js object used for handling binary data. -
querystring
→ A module for parsing and formatting URL query strings. -
url
→ A module for parsing, constructing, and resolving URLs. -
FormData
→ A class used to construct form-data streams for HTTP requests, supporting file uploads. -
xlsx
→ A library for parsing and writing spreadsheet files (Excel), supporting formats like.xlsx. -
papaparse
→ A fast and powerful CSV parser for JavaScript, supporting streaming and large datasets. -
pdfParse
→ A Node.js library to extract text and metadata from PDF files. -
Boltic SDK
→ Official SDK for calling Boltic services directly from Function activities (see the full documentation). -
FDK Client JavaScript
→ JavaScript SDK for interacting with the Fynd Platform, supporting both ApplicationClient and PlatformClient operations (see the GitHub repository and npm package).