Ina Generic Inquiry, when I try to show the value in “Body” field from the “InventoryItem” object, many of the items show coding like HTML coding on a web page with the description at the bottom. We only have a problem with these items when we update that field or copy from that field. Does anyone know what causes this problem and how to properly fix it? Thank you for whatever help you guys could offer. I am using 2019R2 Build 19.209.0038 if anyone needs to know.
HTML coding Shows up in Extended Description Field (InventoryItem.Body)
Best answer by Gabriel Michaud
Hi
The Body field is a Rich Text field that uses HTML to store formatting information:

You need to convert this to plain text before it can be used in a generic inquiry. It would be very nice if we had some sort of function that can be used in the Generic Inquiry (ex: =HTMLToText(Field)), but there’s no such thing. The only way I know involves using customization.
I built a small example for you -- once published, you’ll see a new data access class named InventoryItemPlainTextBodyExt that you can use in your GIs and reports, and a field named BodyPlainText.
Results showing both columns (HTML and Plain Text) side by side:

I have attached the customization to this message.
For technical folks, here’s the code:
using System;
using PX.Objects;
using PX.Data;
namespace PX.Objects.IN
{
public class InventoryItemPlainTextBodyExt : InventoryItem
{
[HtmlToText(typeof(InventoryItem.body))]
[PXUIField(DisplayName="Body (Plain Text)")]
public virtual string BodyPlainText { get; set; }
public abstract class bodyPlainText : PX.Data.BQL.BqlString.Field<bodyPlainText> { }
}
[PXString]
public class HtmlToTextAttribute : PXEventSubscriberAttribute, IPXFieldSelectingSubscriber
{
protected Type _htmlField;
public HtmlToTextAttribute(Type htmlField) :base()
{
_htmlField = htmlField;
}
public void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
e.ReturnValue = PX.Data.Search.SearchService.Html2PlainText(sender.GetValue(e.Row, _htmlField.Name) as string);
}
}
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.