Options

Importing 1000 images in Item table in NAV 2013

diwakar_143diwakar_143 Member Posts: 5
edited 2014-03-29 in NAV Three Tier
Hello Everyone,

I want to import 1000 images in Picture(Blob) field in Item table via processonly report.
The images names are same as Item no. with .bmp format.

Comments

  • Options
    SavatageSavatage Member Posts: 7,142
    If you are going to create a processing report - it will behooooove you to make it flexible.

    Just because you want to import today - doesn't mean you will not need the ability to Export or Delete these images also.

    You can beef up the report to include all 3 options.
    Something like this:

    Variables for Request Form
    ImportItem = boolean
    ExportItem = boolean
    DeleteItem = boolean

    OnAfterGetRecord()
    InvtSetup.GET;
    Item.CALCFIELDS(Picture);
    IF ImportItem THEN ImportItemPicture;
    IF ExportItem THEN ExportItemPicture;
    IF DeleteItem THEN DeleteItemPicture;

    ExportItemPicture()
    IF Item.Picture.HASVALUE
    THEN Item.Picture.EXPORT('c:\temp\'+Item."No."+'.BMP',FALSE);

    DeleteItemPicture()
    IF Item.Picture.HASVALUE THEN BEGIN
    CLEAR(Item.Picture);
    Item.MODIFY;
    END;

    ImportItemPicture()
    CLEAR(Item.Picture);
    IF EXISTS (InvtSetup."Item BMP Path"+Item."No."+'.BMP') THEN BEGIN
    Item.Picture.IMPORT(InvtSetup."Item BMP Path"+Item."No."+'.BMP',FALSE);
    Item.MODIFY;
    END;

    //InvtSetup."Item BMP Path" : I have create a default path for my pictures & saved it in a setup table.
  • Options
    diwakar_143diwakar_143 Member Posts: 5
    Hello Mr. Mohana,

    I had already tried this,but IMPORT function is not working in NAV 2013.I want to do this process in NAV 2013.
  • Options
    diwakar_143diwakar_143 Member Posts: 5
    I am trying this through CreateOutStream function ,but still the images are not uploaded into the item table.
    Please provide me a detail solution regarding this.
  • Options
    diwakar_143diwakar_143 Member Posts: 5
    Create a report with Item as a dataItem

    Variable Type
    F1 File
    MemStream InStream
    OStream OutStream
    PicFileName Text
    FilePath Text

    Item - OnAfterGetRecord()
    PicFileName := STRSUBSTNO('%1%2.png',FilePath,"No.");
    IF FILE.EXISTS(PicFileName) THEN BEGIN
    F1.OPEN(PicFileName);
    F1.CREATEINSTREAM(MemStream);
    Item.CALCFIELDS(Picture);
    Item.Picture.CREATEOUTSTREAM(OStream);
    COPYSTREAM(OStream,MemStream);
    Item.MODIFY;
    F1.CLOSE;
    END;
  • Options
    NormajmNormajm Member Posts: 82
    I would like some help in getting this to work as I have a large number of images to upload. I have created the report as listed and it compiled fine.

    Should this be a process only report? Can the format of picfilename be an excel file with three columns - name of image, path to image, item no. or does it need to be .csv or .txt? Where does the picfilename get entered - in the predata section of the report code? Would it be possible to set up a request page where I could enter the picfilename rather than set it in code so I run this report in smaller batches.

    Thank you
  • Options
    diwakar_ghoshdiwakar_ghosh Member Posts: 11
    Hi Normajm,

    1.It is a process only report.
    2.You can create a table(Item Image) in require database with 3 columns Name of Image,Path,Item No.
    3.Create the same report with Item Image Table as DataItem.

    In request page you can add Item No.

    Variable Type
    F1 File
    MemStream InStream
    OStream OutStream
    PicFileName Text
    FilePath Text
    RecItem Record Item

    Item Image - OnAfterGetRecord()
    PicFileName := STRSUBSTNO('%1%2.png',Path,Image Name);
    IF FILE.EXISTS(PicFileName) THEN BEGIN
    F1.OPEN(PicFileName);
    F1.CREATEINSTREAM(MemStream);
    RecItem.reset;
    RecItem.Setrange("No.","Item No.");
    if RecItem.FindFirst then
    begin
    RecItem.CALCFIELDS(Picture);
    RecItem.Picture.CREATEOUTSTREAM(OStream);
    COPYSTREAM(OStream,MemStream);
    RecItem.MODIFY;
    End
    F1.CLOSE;
    END;

    Please check and modify the code as per your requirement.

    Regards,
    Diwakar
  • Options
    NormajmNormajm Member Posts: 82
    Thank you Diwakar. I haven't had a chance to try this, been tasked with a different project. When I get back to this, will follow up with my results.
  • Options
    NormajmNormajm Member Posts: 82
    Set up the table and modified the report, code is as follows...no errors on compile
    there is one line in the image table...
    Image Name: BF2T Y
    Path: c:\user\Pictures\
    Item No: BF2T Y
    the image is a small .jpg file

    PicFileName:= STRSUBSTNO('%1%2.jpg', Path,"Image Name");
    IF FILE.EXISTS(PicFileName) THEN BEGIN
    F1.OPEN(PicFileName);
    F1.CREATEINSTREAM(MemStream);
    RecItem.RESET;
    RecItem.SETRANGE("No.","Item No");
    IF RecItem.FINDFIRST THEN BEGIN
    RecItem.CALCFIELDS(Picture);
    RecItem.Picture.CREATEOUTSTREAM(OStream);
    COPYSTREAM(OStream,MemStream);
    RecItem.MODIFY;
    END;
    F1.CLOSE;
    END;

    When I run the report I get an error:
    "Filter could not be applied. Could not apply filter "B1 G" to column no. "1" because the field is missing or unavailable."

    Could this be a permission issue, that it is unable to access the path on my pc (Win10Pro)? I'll play with it tomorrow night.
  • Options
    NormajmNormajm Member Posts: 82
    That was a the issue! I set up a folder on the root of the NAV server and ran the report from there. Pictures populated the items as needed.

    Diwakar - thank you so much for your assistance
  • Options
    diwakar_ghoshdiwakar_ghosh Member Posts: 11
    You are welcome.

    Regards,
    Diwakar
Sign In or Register to comment.