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.