Decrement
Subtracts a value from an existing number. This is useful for countdown timers, inventory tracking, and reverse iteration in RPA workflows.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
-
Number - The number to decrement. Default variable name is
numfrom Message scope. Can reference variables from Message, Flow, or Global scope. -
Decrement Value - The value to subtract from the number. Default is
1. Can be a constant, variable, or JavaScript expression.
Output
- Result - The decremented number stored in the specified variable. Default variable name is
numin Message scope.- Scope - Determines where the result is stored (Message, Flow, Global, or Custom)
Examples
Example 1: Countdown Timer
Decrease remaining time or iterations:
// Input Number (from Flow scope)
${flow.remainingItems}
// Decrement Value
1
Output: If remainingItems was 10, the result is 9.
Example 2: Inventory Deduction
Subtract sold quantity from available stock:
// Input Number (from Global scope)
${global.stockLevel}
// Decrement Value (from current order)
${msg.quantitySold}
Output: Updated stock level after sale.
Example 3: Retry Attempts Remaining
Track remaining retry attempts:
// Input Number
${flow.retriesLeft}
// Decrement Value
1
Output: Decreases retry count, useful with conditional logic to stop when reaches 0.
Example 4: Deduct Multiple Values
Decrement by a calculated amount:
// Input Number
${flow.budget}
// Decrement Value (JavaScript expression)
${msg.itemPrice + msg.shippingCost}
Output: Budget decreases by total cost including shipping.
Tips for Effective Use
-
Countdown Pattern:
- Initialize with Assign node (e.g., set to 10)
- Use Decrement in a loop to count down
- Check if value reaches 0 or negative to exit loop
-
Inventory Management:
- Track stock levels by decrementing sold quantities
- Use Global scope for shared inventory across multiple flows
- Implement checks to prevent negative inventory
-
Thread Safety:
- The Decrement node uses mutex locks for Flow and Global scopes
- Safe for concurrent operations in parallel flows
-
Negative Results:
- The node allows results to become negative
- Add conditional logic to check if value drops below a threshold
-
Precision Handling:
- Works with floating-point numbers
- Consider rounding for display purposes
Common Use Cases
- Countdown Timers: Track remaining time, attempts, or iterations
- Inventory Tracking: Deduct sold or consumed items from stock
- Budget Management: Subtract expenses from available budget
- Resource Allocation: Track remaining capacity or quota
- Retry Logic: Count down remaining retry attempts before giving up
Common Errors and Solutions
Error: "Number is not defined"
Cause: The input number variable doesn't exist in the specified scope.
Solution: Initialize the number variable before decrementing:
// First use Assign node to create the variable
${flow.remainingItems} = 100
// Then Decrement can reference it
${flow.remainingItems}
Error: "Decrement value is not a number"
Cause: The decrement value cannot be converted to a number.
Solution: Ensure the value is numeric:
// Wrong
${msg.quantity} // where quantity is "5" (string)
// Correct
${parseFloat(msg.quantity)}
Negative Inventory Problem
Cause: Decrementing below zero without validation.
Solution: Add conditional logic before decrementing:
// Use a Condition node before Decrement
if (flow.stockLevel >= msg.orderQuantity) {
// Proceed with Decrement
} else {
// Handle insufficient stock error
}
Incorrect Scope Leading to Unexpected Values
Cause: Using Message scope instead of Flow/Global scope in loops.
Solution: For values that need to persist across iterations:
- Set Input Number scope to Flow or Global
- Set Output Result scope to the same level
- This ensures the decremented value carries over to the next iteration
Floating-Point Arithmetic Issues
Cause: JavaScript floating-point precision can cause unexpected results.
Solution: For precise calculations (especially financial):
// Work with integers (cents) instead of decimals (dollars)
// Decrement Value
${Math.round(msg.amount * 100)} // Convert to cents
Comparison with Increment
While you can use Increment with negative values to decrement, the Decrement node provides:
- Better Readability: Intent is immediately clear
- Semantic Clarity: Code reviewers understand you're reducing a value
- Positive Values: Use natural positive numbers for decrement amounts