Getting fixed Image URLs to show in my HTML is not the problem I am facing. I'd like to rather display the image I've attached to my Article. Since we are able to upload product images to articles I've tried to reference to the Inventory item.ImageUrl but wasn't able to display a working image preview yet.
Hi @jwestermann17
InventoryItem.ImageUrl contains only name of the attached image that should be used as an associated image.
You can get the full url that you can paste as src parameter using ControlHelper.GetAttachedFileUrl.
I’d suggest trying to add a new unbound field in the customization and try to use it inside your notification.
Here’s an example:
using PX.Data; using PX.Data.BQL; using PX.Objects.IN; using PX.SM; using PX.Web.UI; using System; using System.ComponentModel; using System.Web;
namespace FullImageUrl { // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active public sealed class InventoryItemExt : PXCacheExtension<InventoryItem> { bPXString] bDisplayName("Full Image Url")] public string UsrTIImageUrl { get; set; } public abstract class usrTIImageUrl : BqlString.Field<usrTIImageUrl> { }
bPXString] bDisplayName("Test")] public string UsrTITestString { get { return HttpContext.Current.Request.Url.Host; } } public abstract class usrTITestString : BqlString.Field<usrTITestString> { } }
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active public class InventoryItemMaintExt : PXGraphExtension<InventoryItemMaint> { public void _(Events.RowSelecting<InventoryItem> e) { if (!(e.Row is InventoryItem row) || string.IsNullOrEmpty(row.ImageUrl)) return;
var fileNoteIds = PXNoteAttribute.GetFileNotes(e.Cache, e.Row); var fileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (Guid fileNoteId in fileNoteIds) { var fileInfo = fileGraph.GetFileWithNoData(fileNoteId); if (fileInfo.FullName != row.ImageUrl && fileInfo.Name != row.ImageUrl) continue;
var itemExt = row.GetExtension<InventoryItemExt>(); var imageUrl = ControlHelper.GetAttachedFileUrl(null, fileNoteId.ToString()); itemExt.UsrTIImageUrl = imageUrl; break; } } } }
You can also add PXTrace.WriteInformation(imageUrl); to check the value set into the new field.
If you need more than one picture added to the Notification or the example above didn’t give you desired result - I’d also suggest looking into programmatically creating the notification:
var accountId = PX.Data.EP.MailAccountManager.DefaultSystemMailAccountID; var mailTo = "recipient@test.com"; // replace with your way of getting recipient var mailSubject = "Your subject"; var mailBody = GenerateBody(); // create desired notification in this method PX.Data.EP.NotificationSenderProvider.Notify(accountId, mailTo, null, null, mailSubject, mailBody);