Trouble using .replace() in before business rule on an HTML field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2020 04:53 PM
I have an HTML type field called description. I need to use an onBefore business rule to change a character in the description field. For example: current.description.replace("a","i"); does not work.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2020 05:13 PM
Convert HTML to String first using toString() then replace will work. try this.
current.description.toString().replace("a","i");
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2020 06:49 PM
This did not work. Current code updated bellow, still working on this
var desc = current.description.replace(/(<([^>]+)>)/ig, "");
desc.toString().replace(/i/g,'a');
current.setValue('description',desc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2020 05:22 PM
Hi, replace will only replace the first instance of a value, unless you use a regex.
https://www.w3schools.com/jsref/jsref_replace.asp
Your regex should also ensure that you are not replacing characters which are components of the HTML tags.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2020 06:49 PM
This did not work. Current code updated bellow, still working on this
var desc = current.description.replace(/(<([^>]+)>)/ig, "");
desc.toString().replace(/i/g,'a');
current.setValue('description',desc);