How to convert HTML field value to String value for Description field from catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 08:33 AM
Hi,
URGENT : I have a business rule for to populate description field from catalog item to service request form. but the problem is the description field from catalog item is html type so when i populate it in service request form it is showing value in html form. could anyone help me how to resolve this? what script should i add on to this?
provided the BR i used below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:40 AM
Hi @Amit Pandey ,
I tried it but it is not populating any value from catalog item description to service request description. could you please check it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:44 AM
Hi @SM123
please use below script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
if (gr.next()) {
var description = gr.cat_item.description;
current.description = getFinalText(description);
current.update();
}
})(current, previous);
function getFinalText(text) {
// Replace all <br /> tags with a CRLF
var regX1 = /<br\s\/>/ig;
var text2 = text.replace(regX1, String.fromCharCode(13));
// Replace all remaining HTML tags with ""
var regX2 = /(<([^>]+)>)/ig;
var finalText = text2.replace(regX2, "");
return finalText;
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:57 AM
Hi @Ranjit Nimbalka @Amit Pandey ,
I'm still facing the spacing issue. could you Please check the below ss.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 10:09 AM
Hi @SM123 ,
Please try below code:-
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
if (gr.next()) {
var description = gr.cat_item.description;
current.description = new GlideSPScriptable().stripHTML(gr.cat_item.description;);
current.update();
}
})(current, previous);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 10:28 AM
Hi @Ranjit Nimbalka ,
Thanks for the update. but if you see this below 2 ss. it combined pointers and everything as a paragraph(after "Microsoft Access" there is no pointer). it's still a problem when i give this solution. could you please check if it is possible to achieve it?