- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 10:45 AM
Hi all,
We have a catalog item with a description (Example - "Description of Cat Item"), but this is an HTML field and the escription field of the actual catalog tasks are plain text. From within a workflow I am trying to retrieve the plain text version of the Catalog Item description field, and assign it to the description field in the Catalog Task that's created.
Here's what I've got so far:
task.description = current.cat_item.description.getDisplayValue();
It works in the sense that it populates the Catalog Task description, but the HTML tags are included as well (Example - <p>Description of Cat Item</p>)
I know some old non-ServiceNow tricks where you can use a DIV tag to get to the textContent, but I'm not sure how to go about this in ServiceNow. Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 12:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 12:12 PM
Disregard - I went the route of using a regexp to trim out the tags.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 02:25 PM
Hi Tom,
Would you be willing to share the script you used?
Antone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 05:35 AM
Morning Antone,
- I set the description fields of the individual catalog items to reflect what I want them to say.
- I then use the following script from within the workflow to 1) replace <br /> with true CRLF's (linebreaks), 2) replace all remaining tags with an empty space and 3) assign the newly formatted text to the catalog task's description field.
// Retrieve the 'Description' HTML from the Catalog Item
var text = current.cat_item.description.getDisplayValue();
// Replace all <br /> tags with a CRLF
var regX1 = /<br\s\/>/ig;
var text2 = text.replace(regX1, String.fromCharCode(13));
// Replace all remainging HTML tags with ""
var regX2 = /(<([^>]+)>)/ig;
var finalText = text2.replace(regX2, "");
// Set the Catalog Task's 'Description' field to the raw text of the Catalog Items 'Description' field
task.description = finalText;
I'll likely turn this into a script include and make it a function call at some point, but this get's me by for now. Hope it helps:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 11:02 AM
Thank you!
Tone