Upload product images

Dynamics AX D365 or 2012 does not have good answers for uploading or inserting product images other than manually going into each product / item. DIXF doesn’t do this (you can make it do blobs and images but still, not pretty). I created an x++ job to do this a while back and I will share with you the steps involved and what I did. First off, you will need a way to relate your images to the product / item in AX. If you are lucky, the file name will contain the product id, or at least some relation to the product. In my case the image file name contained the old product number in it ex; D004322_US_img.jpg. All I had to do was strip off everything after the first encounter of “_” and I would have the legacy product id. But what about the AX Product ID? I made the client team create a spreadsheet with all of the legacy product ids and their current AX ID, then I used DIXF to update the products external ID (I could have used any free field, there are a ton) having the spreadsheet data to map (if you have released products then just export them with only those 2 fields, that way you have the template for re-import with the legacy field value in place).

Now we can get to the X++ coding. We can approach 2 ways;

  • Loop through all the released products and check the folder for each product id, if found then insert the product image.
  • Loop through all the images in the file folder and check the released products for a matching product id.

Below is the code that will insert / upload an image for a released product. I have ported this to DIXF as well so that you now have a way to use DIXF import for products and include images! Contact me for that one.

static void uploadProductImage(Args _args)
{
DocuActionArchive docuActionArchive;
EcoResProductImageManagement productImageManagement;
EcoResProductImageThumbnail ecoResProductImageThumbnail;
DocuRef docuRef;
DocuValue docuValue;
EcoResProductImage ecoResProductImage;
InventTable inventTable;

// Locate the released product number - Brian Kinser
// In my case i had renamed all the images to the actual product number
// Then made a method that looped through the folder, locating the product 
// number via the file name

InventTable = InventTable::find("AXD0004");
ttsBegin;
docuRef.TypeId = "File";
docuRef.RefTableId = inventTable.TableId;
docuRef.RefRecId = InventTable.RecId;
docuRef.RefCompanyId = inventTable.dataAreaId;
docuRef.ActualCompanyId = curext();
docuRef.insert();
docuActionArchive = DocuAction::newDocuRef(docuRef);
docuActionArchive.add(docuRef,"C:\\Users\\briankinser\\ProductImages\\AXD0004.jpg");

ecoResProductImage.RefRecId = docuRef.RecId;
ecoResProductImage.RefRecord = docuRef.RefRecId;
//This sets the file name
ecoResProductImage.FileName = "AXD0004.jpg";
//This sets the image usage for the catalog
ecoResProductImage.Usage = EcoResProductImageUsage::External;
//This creates the thumbnail images
ecoResProductImageThumbnail = new EcoResProductImageThumbnail(false);
ecoResProductImage.MediumSize = ecoResProductImageThumbnail.generateThumbnail(204,204,docuRef);
ecoResProductImage.ThumbnailSize = ecoResProductImageThumbnail.generateThumbnail(48,48,docuRef);

if (ecoResProductImage.MediumSize == connull())
{
info("@SYS301935");
}
if (ecoResProductImage.ThumbnailSize == connull())
{
info("@SYS301936");
}
ecoResProductImage.insert();
ttsCommit;
}
Scroll to top