Skip to main content
Solved

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


bjackson29
Freshman I

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.

Best answer by Gabriel Michaud

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

 

 

View original
Did this topic help you find an answer to your question?

5 replies

Gabriel Michaud
Captain II
Forum|alt.badge.img+11

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

 

 


bjackson29
Freshman I
  • Author
  • Freshman I
  • 3 replies
  • March 15, 2021

This is great information.  Thank you Gabriel!


Gabriel Michaud
Captain II
Forum|alt.badge.img+11

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.

 

 


Forum|alt.badge.img
  • Jr Varsity III
  • 49 replies
  • August 19, 2023

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


GlenMartin34
Acumatica Employee
Forum|alt.badge.img
  • Acumatica Employee
  • 69 replies
  • December 10, 2024

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

https://community.acumatica.com/ideas/add-convert-html-to-text-option-in-gis-1088

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings