Solved

HTML coding Shows up in Extended Description Field (InventoryItem.Body)

  • 12 March 2021
  • 4 replies
  • 601 views

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.

icon

Best answer by Gabriel Michaud 12 March 2021, 22:36

View original

4 replies

Userlevel 3
Badge

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

Userlevel 7
Badge +10

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 is great information.  Thank you Gabriel!

Userlevel 7
Badge +10

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

[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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved