Preserve format of Worknotes entered by User in Record

Gayathri Ponse1
Tera Contributor

Hello,

 

I have a requirement where I want to preserve the format of added Work Notes and convert the URLs into clickable hyperlink by user in Demand form. 

 

I have created a business rule before insert update and condition when work notes changes in dmn_demand table. Below is the script:

 

(function executeRule(current, previous /*null when async*/) {

   var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
   var linkTemplate = '[code]<a href="$1" target="_blank">$1</a>[/code]';
   current.work_notes =
'[code]<pre>' + current.work_notes.replace(exp, linkTemplate) + '</pre>[/code]';

})(current, previous);

 

This code is working, however it shows like this below after clicking on Post in Work Notes. It shows us both formatted text and normal text after clicking Post button

worknote issue.PNG

 

Here We want only to display formatted text in Activity Section

https://www.google.com/
Scope     --->         00000

 

Any insights on what the issue could be in the script would be great. I got this script from one of the community questions on a similar issue but do not have a solution for this.

 

Thanks in Advance,

 

2 REPLIES 2

Anand Kumar P
Giga Patron

Hi @Gayathri Ponse1 ,

Try below script in BR.

(function executeRule(current, previous /*null when async*/) {
   var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
   var linkTemplate = '<a href="$1" target="_blank">$1</a>';
   var formattedText = current.work_notes.replace(exp, linkTemplate);
   formattedText = formattedText.replace(/<\/?[^>]+(>|$)/g, "");
   current.work_notes = formattedText;
})(current, previous);

Please mark it as helpful and solution proposed if it works for you.

Thanks,

Anand

Hi Anand,

 

Thanks for the response!

However this script is not working. It is not preserving the same format like below. Spaces are not preserved.

https://www.google.com/
Scope     --->         00000

 

Regards,

Gayathri