- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 03:50 AM
I have a Catalog Item that has a Single Line Text variable, asking the user to enter a cost value. The values may be entered in any one of these forms:
123
123.45
$123.45
1234
$1234
1234.56
$1,234
1,234.56
$1,234.56
I have to do some numerical comparisons on this variable in Flow Designer, i.e. if the value is less than $1,000, do one thing, if it is greater than $1,000, do something else, etcetera (there are actually more than two levels, but I have just simplified it for this example).
I imagine that in order to do these numerical greater than/lesser than comparisons in Flow Designer, I will need to convert my Single Line Text variable to a numerical value. Knowing all the different formats the entry may be in (shown above), how to I convert that entry into a valid number so I can perform those calculation comparisons on it in Flow Designer?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:09 AM - edited 07-31-2025 04:11 AM
Hi @jmiskey
Try the below regex script to remove the non-numeric characters (except .) from the string.
var str = "<Input string>";
// Step 1: Remove any non-digit, non-comma, non-dot characters (like $)
str = str.replace(/[^\d.,]/g, '');
// Step 2: Remove commas
str = str.replace(/,/g, '');
// Step 3: Convert to number
var number = parseFloat(str);
gs.info("Extracted number: " + number);
Output:
Note: Modufy the script as required in the flow to set the output variable value
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:12 AM
why not add a number validation at variable level itself and ask user to enter only number?
Then no need to do any manipulation in flow
You can add this Variable Validation Regex to your variable
OR
If you want user to enter symbol as well while entering amount then you can use your OWN Regex and add it in variable validation Regex OR you can use onChange catalog client script and throw error if validation fails.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:57 AM
Ankur,
While I like your alternative solution (using a RegEx command), there is still one lingering issue with it that needs to be worked out. How do I convert the value into a number to be used in my Flow?
I am trying to create an IF statement that says "if the value is greater than 1000, then proceed...". However, if I choose the variable in an IF action in my Flow, since it is a Single Line Text variable, the only operators available to me are these text options:
Obviously, I need numeric operators like "greater than" and "less than". What is the easiest way to convert this entry to a numeric value in my flow so I can create my IF statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 05:15 AM
I actually found my answer in another thread you replied to: https://www.servicenow.com/community/developer-forum/condition-in-flow-design/m-p/2590131
I just need to use a Flow Variable, and set the Flow Variable equal to the value from my Single Line Text Variable.
I think I have everything I need now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:45 AM
I accepted J Siva's reply as the solution, as that is the one that actually answered the original question asked (even though I like the alternative suggestion better and ended up going with that).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:47 AM - edited 07-31-2025 04:51 AM
I believe I also shared a valid answer and a better approach.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 04:50 AM
That is a nice new feature! I did not realize that existed. I have added yours to the accepted solutions.