The CreatorCon Call for Content is officially open! Get started here.

How to convert HTML field value to String value for Description field from catalog item

SM123
Tera Expert

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

 

 

19 REPLIES 19

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. 

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

 

Hi @Ranjit Nimbalka @Amit Pandey ,

I'm still facing the spacing issue. could you Please check the below ss. 

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

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?