Acumatica - Adding Image in Sales Order Line

2019-07-17 03:00发布

问题:

I am working on making a thumbnail image on the Sales Order lines for the Document Details when the InventoryID is selected. The image however does not populate to the grid whenever I select the InventoryID in the line. Here is what I have so far:

DAC Extension:

namespace PX.Objects.IN
{
  public class InventoryItemExt : PXCacheExtension<InventoryItem>
  {
      #region ThumbnailURL
      public abstract class thumbnailURL : IBqlField
    { }
    [PXString]
    public string ThumbnailURL { get; set; }
      #endregion
  }
}

Code Extension:

using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;

namespace Combined
{
  public class SOLineExt : PXCacheExtension<SOLine>
    {
        #region ThumbnailURL
        public abstract class thumbnailURL : IBqlField
        { }
        [PXString]
        public string ThumbnailURL { get; set; }
        #endregion
    }
    public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
    {
        public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
        {
            baseMethod.Invoke(sender, e);
            if(e.Row!=null)
            {
                var row = e.Row as SOLine;
                if (row.InventoryID != null)
                {

                    InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
                    if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
                    {
                        if(currentLineItem.StkItem==true)
                        {
                            InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                        else
                        {
                            NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

ASPX Code:

Code in the Grid:

<px:PXGridColumn DataField="ThumbnailURL" Width="300px" Type="Icon" />

Code on the InventoryID SegmentMask:

<px:PXSegmentMask CommitChanges="True" ID="edInventoryID" runat="server" DataField="InventoryID" AllowEdit="True" >
  <GridProperties>
    <Columns>
      <px:PXGridColumn Type="Icon" DataField="ThumbnailURL" Width="300px" AutoGenerateOption="Add" />
      </Columns>
    </GridProperties>
</px:PXSegmentMask>

I did find a post about adding an image to the InventoryID Selector and it has a different method of adding images to that grid, does the same apply here? Here is the other post: How to show images inside selector lookup?

I have changed my code above to match the other post but now I am receiving this error:

\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context
\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context

Adding code from the first answer below but now the grid column is showing up blank:

Update 1: FIXED I have redone all the code above to answer 1 along with adding the code from the post of Ruslan's answer in the post above. The screenshot is still coming back the same.

Update 2: I have got everything working or so it seemed. I am now receiving this error only sometimes and I'm not sure what the cause is. Ignore the CustomerID error that is because their credit balance is overdue.

回答1:

Add reference to PX.Web.UI.dll from Acumatica's Bin folder or using PX.Web.UI; if you are writing code in the customization's Code Editor. ControlHelper is a static helper class for making easier work with Acumatica's Web controls .

UPDATE 1

In the answer you have noted addition of the Image is done in the lookup of the Inventory Item Selector and add to the Grid the field of the SOLineExt. In your case you are adding it to the SOLine. Here is code which is doing that:

using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;

namespace ClassLibrary1
{

    public class SOLineExt : PXCacheExtension<SOLine>
    {
        #region ThumbnailURL
        public abstract class thumbnailURL : IBqlField
        { }
        [PXString]
        public string ThumbnailURL { get; set; }
        #endregion
    }
    public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
    {
        public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
        {
            baseMethod?.Invoke(sender, e);
            if(e.Row!=null)
            {
                var row = e.Row as SOLine;
                if (row.InventoryID != null)
                {

                    InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
                    if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
                    {
                        if(currentLineItem.StkItem==true)
                        {
                            InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                        else
                        {
                            NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

As you can see I have added the ThumbnailURL directly to SOLine. Also now it's needed to create instance of the InventoryItemMaint or NonStockItemMaint depending on the Item Type(Stock/NonStock).

As a result you should get this:



标签: acumatica