The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy Description (HTML) content to ootb Description (String)

Sam196
Giga Contributor

I had to create a new Description (HTML) field, so the Service Desk agents can use the field with style formatting (bold italics...). However, for reporting purposes across the company we use the ootb Description (String type) field.

I would like to grab the content from the HTML Description to the ootb String type Description field. I understand the styling won't transfer, but I want the full content to be copied over, including the line breaks as it is.

My role doesn't really involve SNOW development, so I am not really sure what to do here, and if possible I like this to be done without using Client-script. Your help is much appreciated! 

I understand the solution might require some coding, but please keep in mind I cannot code, but I can make sense of what is written in a code. Again, thank you in advance!

1 ACCEPTED SOLUTION

This solution contains one Business Rule

When I update the incident's HTML description field, the current contents is copied and populated into the incidents description field.

Take a look at the images and see if it fits your requirements. Let me know if you need any changes.

 

Business rule configuration:

find_real_file.png

Advanced Tab:

find_real_file.png

Script:

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

	current.description = current.u_html_description; //replace 'u_html_description with your field name for html description'

})(current, previous);

 

Result: (Incidents html field is updated and copied with styling to the Description field)

find_real_file.png

 

It's possible to use a FLOW to do this instead, but I think a business rule is the way to go here and it's very light on the code.

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

View solution in original post

9 REPLIES 9

No problem.

Just replace the script in the business rule with this version:

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

	var htmlString = current.u_html_description; ////replace 'u_html_description with your field name for html description'
	var stringHtml = GlideSPScriptable().stripHTML(htmlString);
	current.description = stringHtml;

})(current, previous);

 

Remember to check what your HTML description field name is and if it isn't 'u_html_description', then update the script with yours.

find_real_file.png

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Sam196
Giga Contributor

Dan - this was really helpful. Sorry to ask again, is there a way to preserve the line breaks?

Example:

HTML:

apple

orange

apple orange

apple

apple orange grapes

STRING TYPE should be like :

apple

orange

apple orange

apple

apple orange grapes

 

Again, you have been extremely helpful, and thank you for the detailed explanation!

Happy to help.

 

Replace script with:

(function executeRule(current, previous /*null when async*/) {
	var desc = current.u_html_description;
	desc = desc.replace(/<\/?[^>]+(>|$)/g, "");
	current.description = desc;

})(current, previous);

 

find_real_file.png

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Sam196
Giga Contributor

Thank you for the quick response. This looks exactly like what we are looking for. I will put it all together and after testing, I will mark your answer correct. Again, thank you so much Dan!

Np, thanks 🙂