How to Safely Calculate Percentages in a Finance Flow Designer Using MVRs and Set Cost Centers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I’m designing a finance workflow in Flow Designer that uses MVRs (Multi-Value Records) to generate accounting entries and allocate amounts to cost centers.
I need to calculate allocated amounts based on a percentage of a total price. Currently, I’m using code like this to handle missing or undefined values safely:
// Get total price safely
var price = parseFloat(fd_data.trigger.request_item.request.price?.value || 0);
// Get percentage safely and round
var perc = Math.round(parseFloat(fd_data._7__for_each.item.percentage || 0));
// Calculate allocated amount
var amount = (price * perc) / 100;
// Return integer amount
return Math.round(amount);
This approach helps prevent errors by:
Using optional chaining (?.) to safely access nested fields.
Defaulting to 0 with || 0 when values are missing.
Parsing values to numbers with parseFloat.
Rounding percentages and allocated amounts to integers using Math.round().
My questions are:
What is the best way to create percentage fields, calculate allocated amounts, and assign cost centers safely in a workflow using MVRs?
How can I fully prevent errors like null, undefined, or NaN (NNN errors) while keeping accounting calculations accurate?
Are there recommended coding patterns or strategies in Flow Designer to ensure calculations do not fail even when fields are missing, empty, or invalid?
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
You’re honestly already doing most of this the right way — its really just about tightening it so it stays reliable as the flow grows.
The biggest thing I see to treat Flow Designer data as untrusted by default. Even when fields are mandatory, MVR rows and data pills can still come through empty depending on how the flow runs.
What I see works well in production:
Validate once, early..
Before you even loop through the MVR, confirm the total price exists and is greater than zero, and that you actually have rows to process. If that’s not true, stop the flow cleanly.Do all math in one place..
Put your calculations in a single Script step or reusable subflow. Convert values to numbers, default missing ones to 0, clamp percentages between 0–100, and calculate the allocation there. This avoids slightly different logic scattered across the flow.Be explicit about bad values..
Assume values can be null, empty, or invalid. If something isn’t a real number, treat it as 0 or exit early. Never let NaN move forward in the flow.Round intentionally..
Do the math using decimals and round only at the very end when assigning the accounting entry. If allocations must total exactly to the original price, track what’s already allocated and put any remainder on the last row.Use flow logic as guardrails..
Mandatory fields, default values, conditions before loops and a clear error path all help prevent partial or incorrect accounting entries.
Bottom line: Validate early, calculate in one place, round once and dont trust incoming values. If you stick to that pattern, your MVR based finance flows will stay predictabel and much easier to support in my experience.
@Prathmeshdagade - Please mark ass Accepted Solution and Thumbs Up if you found Helpful!!
