You need a script with different logic from the example Find and Replace.
The Find and Replace example calculates the new value based on the replacement, then compares the string with the replacement with the original to determine if the record needs updating.
Instead, you need to simply test if the original value includes the string you are looking for. The actual replacement occurs much later in the script when updating the records.
if (originalValue.includes(findText)) {
replacements.push({
record,
before: originalValue,
after: replaceText,
});
}
If you need more assistance than this snippet of code, decide if you want to learn to code, or if you just want working code.
If you want to learn to code, your goal is actually a very good beginning project. However, this particular script has a lot going just to show the preview to the user, which makes reading and understanding the code much harder for a beginner. Without the preview, the code would be much simpler. I find the code snippets in the “API reference” (versus the “Examples”) to be better training tools for people who do not have coding experience.
On the other hand, if you just want working code (and have budget), it will probably be easier to hire someone to write the code for you.
You need a script with different logic from the example Find and Replace.
The Find and Replace example calculates the new value based on the replacement, then compares the string with the replacement with the original to determine if the record needs updating.
Instead, you need to simply test if the original value includes the string you are looking for. The actual replacement occurs much later in the script when updating the records.
if (originalValue.includes(findText)) {
replacements.push({
record,
before: originalValue,
after: replaceText,
});
}
If you need more assistance than this snippet of code, decide if you want to learn to code, or if you just want working code.
If you want to learn to code, your goal is actually a very good beginning project. However, this particular script has a lot going just to show the preview to the user, which makes reading and understanding the code much harder for a beginner. Without the preview, the code would be much simpler. I find the code snippets in the “API reference” (versus the “Examples”) to be better training tools for people who do not have coding experience.
On the other hand, if you just want working code (and have budget), it will probably be easier to hire someone to write the code for you.
Thanks for the code snippet, I will look at the API reference to learn more. I actually accomplished what I needed to using formula fields with IF, OR, and Find but I thought to give it a shot through a script as a learning exercise. I will review other code examples along with the API reference to learn as much as I can. Thanks again!