Microflow Examples
Examples for creating and manipulating microflows programmatically.
To view logs from your code, focus on the extension window and press F12 to open browser dev tools, then check the Console tab.
View Microflow Properties
Inspect all properties of a microflow to understand its structure:
By ID
get-properties-by-id.js
// ============================================
// Get properties by microflow id
// ============================================
const microflowId = 'e5485ede-d256-41db-bc00-26c2fa6cd66a'; // CHANGE THIS
const { microflows } = studioPro.app.model;
const loadedById = await microflows.loadAll(
(info) => info.$ID === microflowId
);
if (loadedById.length > 0) {
const mf = loadedById[0];
// Log the whole object
log('Full object:');
log(mf);
// Try different property names
log(` mf.name = ${mf.name}`);
log(` mf.$QualifiedName = ${mf.$QualifiedName}`);
// Show all property keys
log(`\nAll properties:`);
log(Object.keys(mf));
}What this shows:
- Full microflow object structure
- All available properties and their values
- Property keys you can access
Load Microflow
Load a specific microflow using different methods:
By ID
load-microflow-by-id.js
// ============================================
// Load Microflow by ID
// ============================================
const microflowId = 'e5485ede-d256-41db-bc00-26c2fa6cd66a'; // Change this to your microflow Id
const { microflows } = studioPro.app.model;
const loadedById = await microflows.loadAll(
(info) => info.$ID === microflowId
);
log(`Loaded ${loadedById.length} microflows`);
if (loadedById.length > 0) {
const mf = loadedById[0];
log(`✅ Found: ${mf.name}`);
log(` Qualified Name: ${mf.$QualifiedName}`);
log(` Module: ${mf.$ModuleName}`);
log(` ID: ${mf.$ID}`);
log(` Objects: ${mf.objectCollection?.objects?.length || 0}`);
log(` Documentation: ${mf.documentation || '(none)'}`);
}Key Properties:
$ID- Unique identifier for the microflow$QualifiedName- Full name including module (e.g.,MyModule.MyMicroflow)$ModuleName- The module where the microflow is definedname- Display name of the microflowobjectCollection.objects- Array of microflow activities and flowsdocumentation- Description text for the microflowmicroflowReturnType- Return type of the microflow
Configure ActionActivity
Configure an existing ActionActivity with a RetrieveAction. The ActionActivity must be created first in Studio Pro, then you can configure its action programmatically.
Important: Change the microflowId and activityId to match your own microflow and activity IDs.
Database Retrieve
configure-database-retrieve.js
// ============================================
// Configure ActionActivity with RetrieveAction
//
// NOTE: The ActionActivity must already exist in the microflow
// This code configures that existing activity's action
// ============================================
const microflowApi = studioPro.app.model.microflows;
const microflowId = 'c7124229-515b-439f-b3cd-c02f42897b52'; // CHANGE THIS
const activityId = 'fcfc5395-c1b2-43d6-a0e9-fa88f3105e76'; // CHANGE THIS
try {
const microflows = await microflowApi.loadAll(info => info.$ID === microflowId);
const microflow = microflows[0];
const activity = microflow.objectCollection.objects.find(obj => obj.$ID === activityId);
console.log('=== Configuring ActionActivity ===');
// Create action objects
const retrieveAction = await microflowApi.create('Microflows$RetrieveAction');
const dbSource = await microflowApi.create('Microflows$DatabaseRetrieveSource');
const constantRange = await microflowApi.create('Microflows$ConstantRange');
// Assign relationship FIRST, then set properties
retrieveAction.retrieveSource = dbSource;
dbSource.entity = 'PhoKing.Restaurant'; // CHANGE THIS
dbSource.xPathConstraint = '[id = $Review/PhoKing.Review_Restaurant]'; // CHANGE THIS
constantRange.singleObject = true;
dbSource.range = constantRange;
// Assign action to activity
activity.action = retrieveAction;
// IMPORTANT: Set outputVariableName via container reference (activity.action)
console.log('Setting via activity.action.outputVariableName...');
activity.action.outputVariableName = 'Restaurant'; // CHANGE THIS
console.log(` Set to: '${activity.action.outputVariableName}'`);
await microflowApi.save(microflow);
console.log('✓ Saved');
// Reload to verify
const reloaded = await microflowApi.loadAll(info => info.$ID === microflowId);
const reloadedAction = reloaded[0].objectCollection.objects.find(obj => obj.$ID === activityId).action;
console.log('\n✅ After reload:');
console.log(` Output variable: '${reloadedAction.outputVariableName}'`);
console.log(` Persisted: ${reloadedAction.outputVariableName === 'Restaurant'}`);
} catch (error) {
console.error('ERROR:', error);
}Key Points:
- The ActionActivity must be created first in Studio Pro (manually or via API)
- Assign relationships BEFORE setting properties for correct persistence
- Set outputVariableName via container reference (
activity.action.outputVariableName) - Database retrieve uses entity + XPath constraint
- Association retrieve uses association qualified name + start variable name
- Always verify changes by reloading the microflow after save