Skip to main content

Command Execution Functions

Execute commands and backend operations within your formulas.

doCmd()

Execute a custom command defined in the command library.

Syntax

doCmd(commandName, data)

Parameters

ParameterTypeRequiredDescription
commandNamestringYesName of the command to execute
dataobjectYesData object passed to the command

Returns

Returns the result of the executed command. The return type depends on the specific command.

Examples

Basic Command Execution

var result = doCmd('SendMailCommand', {
Data: {
subject: 'Welcome Email',
email: ['customer@example.com'],
message: '<h1>Welcome!</h1>',
sender: 'noreply@bank.com'
}
});

Execute with Complex Data

var result = doCmd('CreateDepositAccount', {
Data: {
accountName: 'Savings Account',
clientEncodedKey: context.clientEncodedKey,
productEncodedKey: context.productEncodedKey,
branchEncodedKey: context.branchEncodedKey,
currencyEncodedKey: context.currencyEncodedKey,
initialDeposit: 1000.00
}
});

if (result.IsSuccessful) {
console.log('Account created: ' + result.Data.accountNumber);
}

Chain Commands

// Step 1: Create account
var accountResult = doCmd('CreateDepositAccount', {
Data: accountData
});

// Step 2: Send notification
if (accountResult.IsSuccessful) {
var emailResult = doCmd('SendMailCommand', {
Data: {
subject: 'Account Created',
email: [context.email],
message: 'Your account ' + accountResult.Data.accountNumber + ' is ready',
sender: 'accounts@bank.com'
}
});
}

return accountResult;

Notes

  • Commands are loaded from the command library
  • Custom formulas within commands can call other commands
  • Be cautious of circular dependencies
  • Command execution is synchronous within the formula context

doCmd()

Execute a native backend command (BPMCore commands).

Syntax

doCmd(commandName, data)

Parameters

ParameterTypeRequiredDescription
commandNamestringYesName of the native backend command
dataobjectYesData object passed to the command

Returns

Returns the result of the executed backend command. Structure varies by command.

Examples

Execute Loan Schedule Command

var schedules = doCmd('GetExistingLoanSchedules', {
accountNumber: 'LN00001234'
});

console.log('Total Schedules: ' + schedules.summary.totalSchedules);
console.log('Amount Due: ' + schedules.summary.totalDue);

Execute Account Query

var account = doCmd('GetDepositAccount', {
accountNumber: context.accountNumber
});

if (account && account.accountBalance) {
return {
accountNumber: account.accountNumber,
balance: account.accountBalance,
status: account.accountState
};
}

Execute Transaction Command

var result = doCmd('CreditDepositAccount', {
accountNumber: context.accountNumber,
amount: context.amount,
transactionReference: context.reference,
narration: 'Credit Transfer'
});

if (result.IsSuccessful) {
return {
success: true,
newBalance: result.Data.newBalance,
transactionId: result.Data.transactionId
};
}

Batch Processing

var results = [];

context.accountNumbers.forEach(function(accountNo) {
var result = doCmd('GetDepositAccountBalance', {
accountNumber: accountNo
});

results.push({
accountNumber: accountNo,
balance: result.balance
});
});

return {
totalAccounts: results.length,
accounts: results
};

Available Backend Commands

Common backend commands include:

Account Management:

  • CreateDepositAccount
  • UpdateDepositAccount
  • CloseDepositAccount
  • GetDepositAccount

Transactions:

  • CreditDepositAccount
  • DebitDepositAccount
  • TransferBetweenAccounts

Loan Management:

  • CreateLoan
  • ApproveLoan
  • DisburseLoan
  • RepayLoan
  • GenerateLoanSchedules
  • GetExistingLoanSchedules (NEW)

Till/Vault:

  • OpenTellerTill
  • CloseTellerTill
  • FundTellerTill
  • CreateBranchVault

Error Handling

try {
var result = doCmd('RepayLoan', {
accountNumber: context.accountNumber,
amount: context.amount
});

return result;
} catch (error) {
return {
success: false,
error: error.message
};
}

Performance Considerations

  • Backend commands query the database directly
  • Cache frequently accessed data using $.cache functions
  • Avoid calling backend commands in loops when possible
  • Consider batch operations for multiple records

Example: Cached Backend Call

var cacheKey = 'account_balance_' + context.accountNumber;

var balance = $.cache.getOrSet(cacheKey, function() {
var result = doCmd('GetDepositAccountBalance', {
accountNumber: context.accountNumber
});
return result.balance;
}, 60); // Cache for 60 seconds

return balance;

Comparison: doCmd vs doBackend

FeaturedoCmddoBackend
PurposeExecute custom commandsExecute native backend commands
SourceCommand libraryCore system commands
FlexibilityCan contain formulasFixed implementation
PerformanceDepends on formulaOptimized
AuthorizationCommand-specificSystem-enforced
Best ForBusiness logic, workflowsDirect system operations

When to Use Each

Use doCmd() when:

  • Executing business workflows
  • Running multi-step processes
  • Using custom logic defined in command library
  • Need command-level authorization

Use doCmd() when:

  • Performing direct CRUD operations
  • Querying system data
  • Executing core banking operations
  • Need guaranteed system functionality

See Also