Skip to main content

Item Image upload through X++ code

static void TheAxapta_ItemImageUpload(Args _args)
{
    DocuActionArchive               docuActionArchive;
    EcoResProductImageManagement    productImageManagement;
    EcoResProductImageThumbnail     ecoResProductImageThumbnail;
    DocuRef     docuRef;
    DocuValue   docuValue, dv;
    EcoResProductImage  ecoResProductImage;
    EcoResProduct       ecoResProduct;
    InventTable         inventTable;
    Name                imageName  ;
    int                 voucherCounter;
    FilePath               _folderPath;

    System.String[] fileNames;
    int fileCount, i, insertCount;
    str fileName, trimmedFileName, fileNameWithExt;
    BinData binData;
    binData = new BinData();
    //_folderPath = "C:\\Migration\\Products\\DefaultOrderSettings\\";
    fileNames = System.IO.Directory::GetFiles(@"c:\\itemimages\\");
    fileCount = fileNames.get_Length();
    select count(RecId) from dv;
    voucherCounter = any2int(dv.RecId) + 1;
     //clean the product image database
    delete_from ecoResProductImage;
    delete_from docuValue where docuValue.FileType =="jpg";
    delete_from docuRef where docuRef.TypeId == "Image";
   //for (i=0; i<fileCount; i++)
    for (i=0; i<20; 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", "");
         }
        inventTable = InventTable::find(trimmedFileName);
        if(inventTable)
        {
        try
        {
            ttsBegin;

             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.RefRecId = inventTable.RecId;
             docuRef.RefCompanyId = curext();
             docuRef.TypeId = "Image";
             docuRef.insert();
             ecoResProductImage.clear();
             ecoResProductImage.DefaultImage = true;
             ecoResProductImage.FileName = fileNameWithExt;
             ecoResProductImage.ImageFormat = "jpg";
             ecoResProductImage.RefRecId = docuRef.RecId;
             ecoResProductImage.RefRecord = inventTable.recId;
             ecoResProductImage.Usage = 0; // Base Enum: 0=External, 1=Internal
             ecoResProductImage.insert();
             insertCount++;
            ttsCommit;

        }
        catch
        {
            error("Error " + trimmedFileName);
            throw Exception::Error;
        }
      }
    }
    info(strFmt("%1 product images inserted", insertCount));
}

Comments

Popular posts from this blog

D365 : ENABLE AND DISABLE IN LIST PAGE

 here i have added 4 button in salesQuotationlistpage. now i need to enable/disable button according status. so i have Extensionof  of class SalesQuotationListPageInteraction and modify setButtonEnabled method by Chain of Command //list page button enable and diable in listpage interation class [ExtensionOf(classStr(SalesQuotationListPageInteraction))] final class SQTableinimathod_Extension {     protected void setButtonEnabled()     {                SalesQuotationTable SalesQuotationTable;         CustQuotationJour   CustQuotationJour;         CustQuotationConfirmJour  CustQuotationConfirmJour;               next setButtonEnabled();         SalesQuotationTable SalesQuotationTable1 = this.listPage().activeRecord(queryDataSourceStr(SalesQuotationListPage, SalesQuotationTable));         selec...

An error occurred during report data sets execution D365 For finance and operations

  Hi all, small tip. I faced this issue, when I extend the custom report in D365 for finance and operations. During development on onebox     Solution was simple, restart IIS services Restart Reporting Services. Happy Daxing.

CODE TO PDF IN AX 2012

static void Job1(Args _args) {         PurchPackingSlipController      ssrsController = new SrsReportRunController();         TradeDocumentReportContract     purchPackingSlipContract = new TradeDocumentReportContract();         SRSPrintDestinationSettings     printerSettings;         VendPackingSlipJour             VendPackingSlipJour;         Args                            args;         //select the latest record based on create date         while select VendPackingSlipJour             order by VendPackingSlipJour.createdDateTime DESC             where VendPackingSlipJour.PackingSlipId == 'LJ-01'         ...