Recently, I worked on inserting an image from file for a product variant record using X++. No matter, if it is just a product or released product, the process will be the same. The X++ code is shown below:

DocuActionArchive               docuActionArchive;

    EcoResProductImageManagement    productImageManagement;

    EcoResProductImageThumbnail     ecoResProductImageThumbnail;

    DocuRef                         docuRef;

    DocuValue                       docuValue;

    EcoResProduct                   ecoResProduct;

    EcoResProductImage              ecoResProductImage;

    EcoResDistinctProductVariant    ecoResDistinctProductVariant;

// Specify the display product number for which the variant belongs to in find method parameter   

ecoResProduct = EcoResProduct::findByDisplayProductNumber(“DisplayProductNumber”);   

    ttsBegin;

    docuRef.TypeId = “File”;

    docuRef.RefTableId = tableNum(EcoResDistinctProductVariant);

    docuRef.RefRecId = ecoResProduct.RecId;

    docuRef.RefCompanyId = ecoResProduct.dataAreaId;

    docuRef.ActualCompanyId = curext();

    docuRef.insert();

    docuActionArchive = DocuAction::newDocuRef(docuRef);

    docuActionArchive.add(docuRef, “c:\\Users\\Administrator\\Desktop\\Sample.jpg”);

    ecoResProductImage.RefRecId         = docuRef.RecId;

    ecoResProductImage.RefRecord        = docuRef.RefRecId;

    ecoResProductImage.FileName         = “Test”;

    ecoResProductImage.Usage            = EcoResProductImageUsage::External;

    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;

Enjoy!!

Thanks,

Baber.