The Now Platform® Washington DC release is live. Watch now!
‎02-27-2022 07:57 AM
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!
Solved! Go to Solution.
‎02-27-2022 10:09 AM
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:
Advanced Tab:
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)
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
‎02-27-2022 11:41 AM
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.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
‎02-27-2022 12:07 PM
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!
‎02-27-2022 12:16 PM
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);
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
‎02-27-2022 12:18 PM
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!
‎02-27-2022 12:20 PM
Np, thanks 🙂