function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sanjana Rajasekar 9Sanjana Rajasekar 9 

Extract Numbers From Text Values in Flows

Hi,
I have a Text Field (Cost Group) and Discount Field (Discount). I am using a record triggered flow . I need to process the cost group values to extract only the numbers and update to the Discount fields.

Examples of Cost group field values: Air 20, AIR/HUG80, ZM 60%
How can I use this logic in the record triggered flow without using any apex classes.

Thanks
Sanjana
Best Answer chosen by Sanjana Rajasekar 9
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sanjana,

Can you try implementing the logic similar to this.

https://blog.certifycrm.com/salesforce-flow-strip-text-from-a-number/

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Do you need to extract only numbers from the strings like.

From AIR 20 it should return 20
From AIR/HUG80 it should return 80

For Discount field it should return 
From ZM 60% it should return 60.

Can you confirm Cost Group does not contain % at the end and contains numbers only in Last two digits and Discount Field will contain last three digits as number%.

Thanks,
 
Sanjana Rajasekar 9Sanjana Rajasekar 9
Hi @Sai Praveen,
Yes, I need to extract only the numbers from the string. Cost group also containes % at the end and It also contains digits in middle of the String (Eg: AIR 50 ER  must return 50 ) . Discount Field will contain only Extracted Number.

Thanks
Sanjana
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sanjana,

Can you try implementing the logic similar to this.

https://blog.certifycrm.com/salesforce-flow-strip-text-from-a-number/

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Hakuna MatataHakuna Matata
You can use the built-in string functions and formula functions in Salesforce Flow to extract the numbers from the Cost Group field and update the Discount field. Here's how you can do it:
  1. Create a new Record-Triggered Flow on the object where the Cost Group and Discount fields exist.
  2. Add a Record Lookup element to the flow to get the current record's Cost Group and Discount field values.
  3. Add a Formula element to the flow to extract the numbers from the Cost Group field. Here's the formula you can use:
TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Cost_Group__c, '%', ''), '/', ''), ' ', ''))

This formula removes any spaces, forward slashes, and percentage signs from the Cost Group field value, leaving only the numbers. The TRIM function removes any leading or trailing spaces that might have been left after removing the characters.
4. Add an Assignment element to the flow to update the Discount field with the extracted numbers. Here's the formula you can use:
{!Formula_Result}

This formula simply references the output of the Formula element that you created in step 3.
Save and activate the flow.
Now, when a record is created or updated, the flow will run and update the Discount field with the extracted numbers from the Cost Group field.
Note that this solution assumes that the numbers in the Cost Group field are always followed by a non-numeric character, such as a space, forward slash, or percentage sign. If this is not always the case, you may need to adjust the formula accordingly to handle different scenarios.
---
Check also: Manok na pula mod apk
Mahmud Hossain 1Mahmud Hossain 1
Hi Hakuna Matata,
Thank you for your formula. I have one similar request. I have one field where values are like this Orange-13, Banana-21, Yellow-24. And these values are dynamic. I have one requirement like extracting these values and multiply with 12 and then concatenate again like Orange - 156. Do you have any idea how can we do it in flow