Showing posts with label AX 2012. Show all posts
Showing posts with label AX 2012. Show all posts

Monday, 6 April 2015

Restore deleted Sales order in AX 2012


How to Restore deleted sales order or purchase order Ax 2012 ?


If the parameter 'Mark order as voided' is enabled in the Accounts receivable parameters, you can find the deleted order in the form "Voided sales orders" that can be found under Sales and marketing/Inquiries/History/Voided sales orders. 

In fact the history tables contains sent Confirmations, Packing slips and Invoices.

Sales order restoration:

static void restoreDeletedSO(Args _args)
{
SalesTableDelete    salesTableDelete;
SalesLineDelete     salesLineDelete;
SalesTable          salesTable;
SalesLine           salesLine;
;
SalesTableDelete = SalesTableDelete::find(‘00450_036′, true);
ttsbegin;
switch (salesTableDelete.Cancelled)
{
case Voided::Voided :
salesTable  = conpeek(salesTableDelete.SalesTable, 1);
salesTable.insert();
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
}
salesTableDelete.delete();
break;
case Voided::linesVoided :
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
salesLineDelete.delete();
}
salesTableDelete.delete();
break;
}
ttscommit;
}

Thanks & Regards
Sindhu

Wednesday, 6 August 2014

Linking images to Items in Item Master

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