Dynamics Search Engine

Showing posts with label Data Import. Show all posts
Showing posts with label Data Import. Show all posts

Thursday, July 7, 2016

How to export import images or pictures from a table field by X++ code in Microsoft Dynamics AX 2012.

How to export / import a picture or image from a table field by X++ code in Microsoft Dynamics AX 2012.


Applied on: Dynamics AX 2012 R3 CU9.
Prerequisite: Basic Dynamics AX 2012 programming knowledge.
Target audience: AX programmers.Assumption: You are familiar with Dynamics AX 2012.


Below X++ job will explain you how to export an image or picture from Dynamics AX 2012 table. It's a simple piece of code but sometimes we spent hours to get the code how to export picture or image. I have posted here just to make it handy.


static void exportImageFromTable(Args _args)
{
    bindata             bin = new bindata();
    str                 content;
    container           image;
    RetailImages        retailImages;
    FilePath            filepath;
   
   
    select retailImages where retailImages.PictureId == 8045;
   
    filepath = strFmt('C:\\Users\\Administrator\\AppData\\Local\\Temp\\images\\PictureID_%1.jpg', retailImages.PictureId);
    image = retailImages.picture;
    bin.setData(image);
   
    // Create the base64 encoded string
    // content = bin.base64Encode();
    // info(content);
   
    // Save it to the file system as a jpg, png or tif format
    AifUtil::saveBase64ToFile(@filepath, content);
   
}


In addition I am share the code how to import or insert a picture or image in Dynamics AX 2012 using X++ code.

Here is the job:

static void InsertImageToTableField(Args _args)
{
   
    Bindata         binData = new BinData();
    FilePath        path;
    RetailImages    retailImages;
    str             imageID;
   
    path = "C:\\Users\\Administrator\\AppData\\Local\\Temp\\Images\\PictureID_8046.jpg"; // file location
   
    binData.loadFile(path);
   
    select retailImages where retailImages.PictureId == 1111;
   
    if (!retailImages)
    {
        retailImages.picture    = binData.getData();
        retailImages.PictureId  = 1111;
        retailImages.doInsert();
    }
   
}


Hope this was useful. You may leave your comment below.





Monday, June 20, 2016

How to export data in a csv or comma separated file by X++ code in Microsoft Dynamics AX 2012


In Microsoft Dynamics AX 2012 how to export data in a csv or comma separated file by X++ code.

This article explains how to generate a csv or comma separated file and export data from Microsoft Dynamics AX 2012 by X++ code.



Applied on: Dynamics AX 2012 R3 CU9.
Prerequisite: Basic Dynamics AX 2012 programming knowledge.
Target audience: AX programmers.
Assumption: You are familiar with Dynamics AX 2012.



I prepared a x++ job here which will guide you how to generate a csv file with a header and one sample line. If you have one header and multi line, you may keep line in a while.



static void exportDataInCSV(Args _args)

{

    Dialog          dialog  = new Dialog();

    DialogField     dialogFieldFileSave;

    Commaio         file;

    container       line;

    FilePath        TempPath;



    dialogFieldFileSave     = dialog.addField(extendedTypeStr(FilenameSave),"File path","Help text goes here");

    dialog.caption("Caption goes here");

    dialog.filenameLookupFilter(['csv','*.csv']);



    if(!dialog.run())

        return;



    if (dialogFieldFileSave.value() == '')

    {

        error("Please set up the location for export file.");

        return;

    }



    TempPath = dialogFieldFileSave.value() + '.csv';



    #define.filename(TempPath)

    #File





    file = new Commaio(#filename , #io_write);

    if( !file || file.status() != IO_Status::Ok)

    {

        throw error("File Cannot be opened");

    }



    //Put headers

    line = ["CardNum","Amount","IssueDate","ExpiryDate","IssueBy","CustAccount","Description"];

    file.writeExp(line);



    //Put a sample line

    line = ["C_476786","100.00","05/26/2015","03/25/2016","John Smith S","Cust_0000034","Description"];

    file.writeExp(line);



    info(strFmt("File exported successfully. Please find it at %1",TempPath));

}





Hope this was useful. You may leave your comment below.








Tuesday, February 24, 2015

How to fix Data Migration Framework (DIXF) error in Microsoft Dynamics AX 2012 R3

How to fix Data Migration Framework (DIXF) error in Microsoft Dynamics AX 2012 R3

 
This article addresses:
How to resolve Data Import / Export Framework (DIXF) error.
How to resolve data upload error in Microsoft Dynamics AX 2012.
How to resolve error ‘could not load file or assembly … The system cannot find the file specified.




Applied on: Dynamics AX 2012 R3.
Prerequisite: Basic Dynamics AX 2012 programming knowledge.
Target audience: AX programmers.
Assumption: You are familiar with Dynamics AX 2012.

When you get an error to upload data using Data Migration Framework (DIXF), check below things.

- Data Import / Export Framework (DIXF) service should be installed on a computer running SQL Server Integration Services. This component provides the connection to SQL Server Integration Services.
In order to complete the installation, you must provide an account for the service to run as. AOS service account is recommended.
 

- AOS component should be installed on AOS server that connects the AOS to the Data Import/Export Framework service. If AOS component is installed correctly you should get a folder called  DataImportExportFramework under default location “C:\Program Files\Microsoft Dynamics AX\60” on AOS server. Inside this folder you should have:

DMFConfig
Microsoft.Dynamics.AX.Framework.Tools.DMF.DriverHelper
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.exe


- Client component should be installed on client system. It installs the user interface component of the Data Import/Export Framework. If client component is installed correctly the client bin folder should have 4 DLLs e.g.

Microsoft.Dynamics.AX.Framework.Tools.DMF.DriverHelper.dll, Microsoft.Dynamics.AX.Framework.Tools.DMF.Mapper.dll, Microsoft.Dynamics.AX.Framework.Tools.DMF.PreviewGrid.dll, Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.dll

The default location for these files is “C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin” on client machine. Your AOS server can be a client as well.
 

-     Open your AX client and go to Data import export framework module > Setup > Data import/export framework parameters. On this form you need to define a share folder path and validate. Important thing is the service account assigned to Data Import / Export Framework (DIXF) service on SQL server should have access to this folder.

 

-      On AOS server go to Start > Administrative Tools > Server Manager > Configuration > Local Users and Groups > Groups. In this Groups folder there must a group called Microsoft Dynamics AX Data Import Export Framework Service Users. In this group add service account (user ID) which you used for DIXF on SQL server. Also add users will be accessing DIXF.
 

-      Open your AX client and go to System administration > Setup > Services and Application Integration Framework > Inbound ports > make sure DMFService is activated.

 
Hope this was useful for you. Leave your comment below

Tuesday, February 21, 2012

In Microsoft Dynamics AX 2012 during data import using Excel Add-Ins you may experience an exception or error

In Microsoft Dynamics AX 2012 during data import using Excel Add-Ins you may experience an exception like: “You must include at least two items in any list used for updating data.”

Applied on:
Microsoft Dynamics AX 2012 CU2.

Assumption:
This article is for those who has at least basic data flow and navigation
knowledge.

About this article:
This article may answers your question like-
• In Microsoft Dynamics AX 2012 how to handle exception during data import or data conversion?
• In Microsoft Dynamics AX 2012 how to copy master data from one environment to another environment and handle exception or error?
• In Microsoft Dynamics AX 2012 what are the new feature to export / import data?

Exception:

Resolution:
During data import using Excel Add-ins tool you need to select table(s). Once the table(s) is selected, by default system will select field(s) from table which is mandatory or part of primary index. If you have more than two fields like this then you will not face this exception or error. If there is one field which is mandatory or part of primary index in your table then system will select that field and put in the excel sheet and manually you need to select one more field along with this. In the above error screen if you see the red marked area where one more field to be added to get out of this exception.
Hope this is useful.