Trouble using .replace() in before business rule on an HTML field

Community Alums
Not applicable

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.

6 REPLIES 6

MrMuhammad
Giga Sage

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

Regards,
Muhammad

Community Alums
Not applicable

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);

Tony Chatfield1
Kilo Patron

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.

Community Alums
Not applicable

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);