Showing posts with label Upload product image Dynamics AX. Show all posts
Showing posts with label Upload product image Dynamics AX. Show all posts

Tuesday, 27 March 2018

Update Product Images in Microsoft Dynamics AX 2012

Introduction:
Microsoft Dynamics AX 2012 contains a helper class that can be used to attach images to a product. The images can either be a location on file system or hosted somewhere on web. To upload a product's image using X++ in Dynamics Ax 2012, you can use the following code snippet

Code Snippet:
    EcoResProductImageManagement        ecoResProductImageManagement;
    RefRecId    productRecId;

    //EcoResProductImageManagement class is helper class for image management
    ecoResProductImageManagement = EcoResProductImageManagement::construct();
   
    //Assign respective Document Type Id, URL incase the image location is Web or File, if the iamge is stored in file system
    ecoResProductImageManagement.parmDocuTypeId('URL');
       
    //The image location is provided by a url path or file system path and then define the actual location of the image file
    ecoResProductImageManagement.parmIsUrlPath(true);
    ecoResProductImageManagement.parmImage("http://sampleimage.com/300442.JPG", '', EcoResProductImageUsage::External, true);
   
    //Details of the product to which image needs to be assigned
    ecoResProductImageManagement.parmRefRecId(productRecId);
    ecoResProductImageManagement.parmRefTableId(tablenum(InventTable));
    ecoResProductImageManagement.parmDataAreaId(curext()); 
   
    //execute the process, it will assign the image to the provided product
    ecoResProductImageManagement.submit();