Skip to main content

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.

Hi @bjackson29,

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> { }
}

bPXString]
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);
}
}
}

 

 


This is great information.  Thank you Gabriel!


I wished I could edit my reply -- there’s an attribute missing in the fields which means the Plain Text Body will be blank when you don’t include the HTML Body in your generic inquiry. The solution is to add PXDependsOnFields to the DAC:

 

 public class InventoryItemPlainTextBodyExt : InventoryItem
{
>HtmlToText(typeof(InventoryItem.body))]
>PXDependsOnFields(typeof(InventoryItem.body))]
>PXUIField(DisplayName="Body (Plain Text)")]
public virtual string BodyPlainText { get; set; }
public abstract class bodyPlainText : PX.Data.BQL.BqlString.Field<bodyPlainText> { }
}

Updated project is attached.

 

 


This still a valid and beautiful solution. Just implemented it, thanks!


There is an Idea here to add this feature to the core product: 

 


Reply