2

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: Blank Column Issue

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. enter image description here

Community
  • 1
  • 1
Dane
  • 163
  • 14
  • The same steps should apply correctly. You can just skip the part about modifying the Selector, since your image should apply directly to the SOLine – Simon ML Apr 25 '18 at 18:58
  • I have tried the code from the other post and I am getting this as a compiler error: The name 'ControlHelper' does not exist in the current context – Dane Apr 25 '18 at 19:08
  • Updated the code above. – Dane Apr 25 '18 at 19:39

1 Answers1

2

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:

enter image description here

Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46
  • I have added that reference but the column is still showing blank. There is no column header as it is just blank, i'm sure that's just adding the PXUIField properties but the picture does not show. The aspx code on the grid is still the same as above. – Dane Apr 26 '18 at 13:14
  • @Dane can you please unpublish/publish the customization and send me screenshot of the grid showing blank column – Samvel Petrosov Apr 26 '18 at 13:47
  • Added to the original post above. – Dane Apr 26 '18 at 13:57
  • Oh no, I have not added the image to the InventoryID selector. I just want it on the SOLine and not the InvenotryID selector. Should I just remove the ThumbnailURL in the InventoryItemExt? Will that effect your code? – Dane Apr 26 '18 at 15:05
  • @Dane No, you shouldn't .My code is not adding it to the selector. It is adding the Image to the Sales Order Line. You have used the code from the answer where RuslanDev had added the image to the selector – Samvel Petrosov Apr 26 '18 at 15:19
  • Is there anything that needs to happen for this to provoke? I creating a Sales Order, adding a line at the bottom and selecting an item that has an image attached to the ImageUrl. After it is selected the ThumbnailURL field is just still an editable text field, even though it is set to icon. – Dane Apr 26 '18 at 15:33
  • @Dane have you added the code I had posted in the update? Please check that you have added the GridColumn to the Aspx to the InventoryID px:PXSegmentMask as it's done in the Ruslan's answers point 3 – Samvel Petrosov Apr 26 '18 at 15:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169883/discussion-between-dane-and-samvel-petrosov). – Dane Apr 26 '18 at 16:22
  • We have this working now. However, the images are massive in the grid. Is there a way to cut them down by height? – Dane May 18 '18 at 14:26