How to Insert Image in Ax table Using X++ in Ax 2012

Description:- In this Example we will see How to Insert Image in Ax table and Retrieve from Sql. First Create table in Ax and Create Jo for insert image in table.

Create table from AOT Node.
Step 1: Create Table Name it “A_ImageTable”. And Insert Container Filed in Table.
  • Expand AOT Node.
  • Open Data Dictionary Node.
  • Select Tables and right Click Select New Table.
  • Name it “A_ ImageTable”.
  • Now open table in Insert Some Data in A_ ImageTable table.

Create Job from AOT

  • In the AOT, click Job.
  • Right-click the Job node, and then select New Job.
static void ImageField(Args _args)
{
    BinData binData = new BinData();
    A_ImageTable table;
    dialog               d;
    Dialog                      dialog = new dialog();
    dialogField                 dialogFilename;
    //COM wordDocuments;
    FileName                    fileName;
    container imageContainer;
    str imageFilePathName;
    d = new dialog();
    d.caption("select a Image file");
    dialogFilename = d.addField(extendedTypeStr(FilenameOpen),"File Name");//add a field where you select your file in a specific path
    d.run();//execute dialog
    if(d.closedOk())
    {
        filename = dialogFileName.value();//return path file value
    }
    imageFilePathName=filename;
    if ( WinAPI::fileExists(imageFilePathName))
    {
        binData.loadFile(imageFilePathName);
        imageContainer = binData.getData();
        //table.Image = _Party.RecId;
        table.Image = imageContainer;
        table.insert();
    }
}

Now run your Created Job and Select Image File for FileDialogBox and Click OK and See Output in your table.

Related Posts

Previous
Next Post »

1 comments:

comments
June 18, 2018 at 5:14:00 PM GMT+5:30 delete

another way to store into table and also into folder

#define.jpeg('.jpg')
#define.openMode("R")
Dialog dialog;
DialogField dialogFileName;
FileIoPermission perm;
FilePath filePath;
FileName fileExt;
FileName fileName;
Filename fileNameWithPath;
Bindata daxRead, daxSave;
DS_ImageTable imageTable;
container readPic;
str daxBase64;

dialog = new Dialog("File Upload Example");
dialog.addGroup("Image file upload");
dialogFileName = dialog.addField("fileNameOpen", "Select JPEG image file to import");
dialog.run();

if (dialog.run())
{
fileNameWithPath = dialogFileName.value();
if(!fileNameWithPath)
{
throw error("Filename must be filled");
}

[filePath, fileName, fileExt] = fileNameSplit(fileNameWithPath);
if (fileExt != #JPEG)
{
throw error(strFmt("The extension %1 is not allowed.The correct extension should be %2.", fileext, #JPEG));
}

perm = new FileIoPermission(fileNameWithPath, #openMode);
if (perm == null)
{
throw error("No rights to perform this action");
}

perm.assert();
daxRead = new BinData();
daxSave = new BinData();

if (daxRead.loadFile(fileNameWithPath))
{
// Reading and storing image into the container
readPic = daxRead.getData();
imageTable.Image = readPic;
imageTable.Name = fileName;
imageTable.insert();

}
CodeAccessPermission::revertAssert();

// Writing the image to a file from the container
daxSave.setData(readPic);
daxBase64 = daxSave.base64Encode();
AifUtil::saveBase64ToFile(@"D:\\Dipen Task\\Upload Images\\" + fileName + ".jpeg" , daxBase64);
}

Reply
avatar

Thanks for comments.....