How to link an image to an item in Item Master in AX 2012?
1) Copy the images in the required path.2) Create a new job to link images to items.
static void uploadProductImages(Args _args)
{
DocuRef docuRef;
DocuValue docuValue;
InventTable inventTable;
EcoResProductImage ecoResProductImage;
System.String[] fileNames;
int fileCount, i;
str fileName, trimmedFileName, fileNameWithExt;
BinData binData;
str filePath;
System.IO.FileInfo fileInfo;
EcoResProduct ecoResProduct;
EcoResProductImageManagement productImageManagement;
EcoResProductImageThumbnail ecoResProductImageThumbnail;
filePath = 'Specify the path where your images are saved here.';
// File path should be provided as : C:\\Images\\Car.jpg
binData = new BinData();
fileNames = System.IO.Directory::GetFiles(filePath);
fileCount = fileNames.get_Length();
ttsBegin;
for (i=0; i<fileCount; i++)
{
fileName = fileNames.GetValue(i);
// Get only the file name. If value returned is C:\Images\Car.jpg, get only Car.jpg
trimmedFileName = substr(fileName, strscan(fileName, '\\', strlen(fileName),
-strlen(fileName))+ 1, strlen(fileName));
fileNameWithExt = trimmedFileName;
if (trimmedFileName)
{
// Assuming file extension is always .jpg, removing it
trimmedFileName = strreplace(trimmedFileName, ".jpg", "");
}
// assuming image name matches item name in AX
ecoResProduct = EcoResProduct::findByDisplayProductNumber(trimmedFileName);
inventTable = InventTable::findByProduct(ecoResProduct.RecId);
if (inventTable)
{
binData.loadFile(fileName);
docuValue.FileName = trimmedFileName;
docuValue.FileType = "jpg";
docuValue.OriginalFileName = fileNameWithExt;
docuValue.File = binData.getData();
docuValue.insert();
docuRef.ValueRecId = docuValue.RecId;
docuRef.RefTableId = tableNum(InventTable);
docuRef.Name = trimmedFileName;
docuRef.RefRecId = inventTable.RecId;
docuRef.RefCompanyId = inventTable.dataAreaId;
docuRef.TypeId = "Image";
docuRef.insert();
ecoResProductImage.clear();
ecoResProductImage.DefaultImage = true;
ecoResProductImage.FileName = fileNameWithExt;
ecoResProductImage.ImageFormat = "jpg";
ecoResProductImage.RefRecId = docuRef.RecId;
ecoResProductImage.RefRecord = docuRef.RefRecId;
ecoResProductImage.Usage = EcoResProductImageUsage::External;
//0; // Base Enum: 0=External, 1=Internal
// To make the thumbnail size
ecoResProductImageThumbnail = new EcoResProductImageThumbnail(false);
ecoResProductImage.MediumSize = ecoResProductImageThumbnail.generateThumbnail(204,204,docuRef);
ecoResProductImage.ThumbnailSize = ecoResProductImageThumbnail.generateThumbnail(48,48,docuRef);
ecoResProductImage.insert();
info(strFmt("%1 - %2", docuValue.RecId, docuRef.RecId));
}
}
ttsCommit;
}
3) Make sure you have a document type of type "Image"(as we are linking images to items) created in
Organization Administration > Setup > Document Management > Document Types.
Thanks & Regards
Sindhu
Halo,I'm Helena Julio from Ecuador,I want to talk good about Le_Meridian Funding Service on this topic.Le_Meridian Funding Service gives me financial support when all bank in my city turned down my request to grant me a loan of 500,000.00 USD, I tried all i could to get a loan from my banks here in Ecuador but they all turned me down because my credit was low but with god grace I came to know about Le_Meridian so I decided to give a try to apply for the loan. with God willing they grant me loan of 500,000.00 USD the loan request that my banks here in Ecuador has turned me down for, it was really awesome doing business with them and my business is going well now. Here is Le_Meridian Funding Investment Email/WhatsApp Contact if you wish to apply loan from them.Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.comWhatsApp Contact:+1-989-394-3740.
ReplyDelete