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

Process of Sales order in Technical terms in D365Fo

 🔥 Sales Order Technical Flow in D365FO (Creation → Confirmation → Picking → Packing Slip → Invoice → Accounting) 1. Sales Order Creation Tables SalesTable → SO header SalesLine → SO lines CustTable → Customer master InventDim / InventDimCombination → Dimensions InventTable / EcoResProduct → Item master Framework Classes SalesTableType / SalesLineType Responsible for validation, defaulting, creation logic Key Methods SalesTable.initValue() SalesLine.initFromSalesTable() SalesTable.validateWrite() SalesLine.validateWrite() Events (Extensions) SalesTableType.createSalesTable() SalesLineType.createSalesLine() 2. Reservation (Optional) If reservation is done: Tables InventTrans (Reservation status) InventReservation Classes InventUpd_Reservation InventTransReservation Reservations impact picking and inventory availability. 3. Sales Order Confirmation Confirms order and freezes price/quantity. Posti...

Top 200 Q&A in D365FO Technical

  SECTION 1 — X++ BASICS (10 Q&A) 1. What is X++? A proprietary object-oriented language used in Dynamics 365 Finance & Operations for business logic, similar to C# but integrated with D365 runtime. 2. What is a TableBuffer? It is an in-memory object referencing a table. Example: CustTable custTable; 3. What is difference between select and select firstonly ? select → returns all matching rows firstonly → returns only the first matched row 4. What is ttsbegin & ttscommit ? Used to wrap database transactions; ensures atomicity. 5. Can we write SQL queries directly in X++? No. X++ uses a database-abstracted select statement. 6. What is a container? A collection datatype used to store mixed data types. 7. Difference between container and map? Map stores key-value pairs; container is indexed and immutable. 8. What is a temp table? A table that stores data temporarily in memory or database depending on property. 9. What is recursion in X++? A method c...

Process of Purchase order in Technical terms in D365Fo

  Purchase Order Technical Flow in D365FO (Step-by-Step) (From creation → approval workflow → posting → product receipt → invoice → accounting) 1. Purchase Order Creation Tables involved PurchTable → PO header PurchLine → PO lines VendTable → Vendor master InventDim / InventDimCombination → Item dimensions EcoResProduct / InventTable → Item master Classes / Framework PurchTableType / PurchLineType Framework that controls creation, validation, defaulting. Key methods PurchTable.initValue() PurchLine.initFromPurchTable() PurchTable.validateWrite() PurchLine.validateWrite() Events (Extension points) PurchTableType.createPurchTable() PurchLineType.createPurchLine() 2. Purchase Order Confirmation Document Status update PurchTable.DocumentState → Confirmation PurchParmBuffer tables used for versioning. Posting Class PurchFormLetter_Confirm Called internally via PurchFormLetter::construct(DocumentStatus::Co...