Solved

How Can I get Description of an Stock Item to show in a column of another screen?

  • 24 October 2022
  • 4 replies
  • 282 views

Userlevel 4
Badge +1

I want to show the description of a stock item in a column of another screen. But when I was trying to set it in the normal way, it just gives the html code(see the below screenshot),not the actual description sentences.

 

Following is the code that I tried,

 

InventoryItem item = new PXSelect<InventoryItem, Where<InventoryItem.inventoryID,     Equal<Required<InventoryItem.inventoryID>>>>(Base).Select(row.InventoryID);

            if(item != null)
            {
                rowExt.UsrItemDescription = item.Body;
            }

 

How can I show the actual description of that item in my custom column instead of showing html code.

Any help?

icon

Best answer by charithalakshan49 28 October 2022, 08:07

View original

4 replies

Userlevel 5
Badge +2

@charithalakshan49 

You should use Descr field instead

rowExt.UsrItemDescription = item.Descr;

Remember that you can use the Inspect Element feature of the pages to select an existing control and identify the elements that comprise it:

 

Userlevel 4
Badge +1

@Fernando Amadoz Thanks for the response. No I want this field. Not that description.

 

Userlevel 5
Badge +2

@charithalakshan49 that control is of the type <px:PXRichTextEdit>

Those types of control store HTML information so that users can add HTML elements to the record i.e. colors, headers, images, etc.

If you are looking to display the text from that field elsewhere, you would have to parse the HTML and take the needed elements off it.

Realistically, it may be simpler for you store the information in a regular PXTextEdit custom field instead.

Userlevel 4
Badge +1

@Fernando Amadoz Thanks for the idea. However I code as follows to get the description text only by replacing html syntax and other unnecessary words.

            if(item != null)
            {
                rowExt.UsrRRP = Convert.ToDecimal(item.RecPrice);
                rowExt.UsrWeight = item.BaseItemWeight.ToString();
                rowExt.UsrVolume = item.BaseItemVolume.ToString();

                //Set Description field value
                if (item.Body != null)
                {
                    string HTMLCode = item.Body;

                    // Remove new lines since they are not visible in HTML
                    HTMLCode = HTMLCode.Replace("\n", " ");

                    // Remove tab spaces
                    HTMLCode = HTMLCode.Replace("\t", " ");

                    // Remove multiple white spaces from HTML
                    HTMLCode = Regex.Replace(HTMLCode, "\\s+", " ");

                    // Remove HEAD tag
                    HTMLCode = Regex.Replace(HTMLCode, "<head.*?</head>", ""
                              , RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    // Remove any JavaScript
                    HTMLCode = Regex.Replace(HTMLCode, "<script.*?</script>", ""
                      , RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    // Replace special characters like &, <, >, " etc.
                    StringBuilder sbHTML = new StringBuilder(HTMLCode);

                    // Note: There are many more special characters, these are just
                    // most common. You can add new characters in this arrays if needed
                    string[] OldWords = {"&nbsp;", "&amp;", "&quot;", "&lt;",
                                        "&gt;", "&reg;", "&copy;", "&bull;", "&trade;","&#39;"};
                    string[] NewWords = { " ", "&", "\"", "<", ">", "�", "�", "�", "�", "\'" };
                    for (int i = 0; i < OldWords.Length; i++)
                    {
                        sbHTML.Replace(OldWords[i], NewWords[i]);
                    }

                    // Check if there are line breaks (<br>) or paragraph (<p>)
                    sbHTML.Replace("<br>", "\n<br>");
                    sbHTML.Replace("<br ", "\n<br ");
                    sbHTML.Replace("<p ", "\n<p ");

                    var text = System.Text.RegularExpressions.Regex.Replace(
                                       sbHTML.ToString(), "<[^>]*>", "");

                    rowExt.UsrItemDescription = text;
                }

 

 

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