auto importing images

asemberengasembereng Member Posts: 220
How can i import images base on a naming convention. Each image name is the primary id for the employee. All these images will be stored on a directory and what i want to achieve on navision is to click a command button and then all images will be imported for the respectively employee and if the picture for an employee is not found it should be a message allowing the user to manually import the picture,...

Thanks

Comments

  • garakgarak Member Posts: 3,263
    edited 2009-02-11
    Take a look behind form 5202.
    Don't forgett, NAV can only display bitmaps.
    Don't forgett, that is it not a good idea to store big pictures in the table because it's bad for the performance (for this theme exist a lot of topics here).
    So, that your pictures are stored in a directory is not so bad.
    You can store the UNC path (also for this exist topics here) and the filename + extension.
    If a user need to display this image open it with running open the image self with, for example, "Paint" or the default application for bmp.
    With this you have also the posibility to store all image type and not only bmp.

    viewtopic.php?f=23&t=25060
    Do you make it right, it works too!
  • ara3nara3n Member Posts: 9,256
    create a processing report the dataitem will be employee.


    onaftergetRecord Trigger add the following code.


    Picture.import('c:\pictureFolder\'+"No."+'.bmp',false);

    Modify(true);


    Run the report. change the pictureFolder to correct directory.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • SavatageSavatage Member Posts: 7,142
    Your could create a report that runs on a button click.
    something like import pics for all employees that don't alreay have a pic....
    OnAfterGetRecord
    If NOT Employee.Picture then begin
    IF EXISTS ('YourDrive:\YourDirectory\'+Employee."No."+'.BMP') 
     THEN BEGIN
      Employee.Picture.IMPORT('YourDrive:\YourDirectory\'+Employee."No."+'.BMP',FALSE);
      Employee.MODIFY;
     END;
    END;
    

    Damn you guys are quick
  • asemberengasembereng Member Posts: 220
    savatage i am getting the prefix operator cannot be used on blob. Any idea?
  • garakgarak Member Posts: 3,263
    edited 2009-02-11
    change \ to \\

    and change
    if NOT Employee.Picture then begin
     ....
     ....
    end;
    

    to
    Employee.calcfields(Picture); 
    if not Employee.Picture.hasvalue then begin
     .....
     .....
    end;
    
    Do you make it right, it works too!
  • asemberengasembereng Member Posts: 220
    I guess its referring to the NOT
  • asemberengasembereng Member Posts: 220
    and also i want it to skip and employee if it does not see his picture but yet still display an message.
  • asemberengasembereng Member Posts: 220
    thanks alot. Its importing..
  • garakgarak Member Posts: 3,263
    how many empoyees do you have and how big (size) are your bitmaps?
    Do you make it right, it works too!
  • asemberengasembereng Member Posts: 220
    currently its about 90,000 and it will be growing.
  • ara3nara3n Member Posts: 9,256
    asembereng wrote:
    currently its about 90,000 and it will be growing.
    :shock:
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    asembereng wrote:
    currently its about 90,000 and it will be growing.
    Are you really sure that you need them in the database? There are some performance and other consequences in this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    asembereng wrote:
    currently its about 90,000 and it will be growing.

    90000 empoyees and for everyone, or for every second / 3rd a large bitmap?
    Do you need really all 90000 empl. for example for "Wage and salary"
    If yes don't import the bitmaps, use the solution with the UNC path.
    Do you make it right, it works too!
  • asemberengasembereng Member Posts: 220
    I was wondering if i can store this images link only into the database while the actual image stored on a directory, how can i achieve that?
    I bet you, by next year the employees will increase. These database handles the social security system of our country. Not all employees are registered for that matter.
  • ara3nara3n Member Posts: 9,256
    create a new field called "Picture location" as text 250 characters.

    Fill in the UNC path in into field.


    On the employee card add the field and add a button called Open.
    OnPush trigger of the button add
    Hyperlink("Picture location");
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • garakgarak Member Posts: 3,263
    or follow the links in my first post
    Do you make it right, it works too!
  • SavatageSavatage Member Posts: 7,142
    asembereng wrote:
    I was wondering if i can store this images link only into the database while the actual image stored on a directory, how can i achieve that?
    I bet you, by next year the employees will increase. These database handles the social security system of our country. Not all employees are registered for that matter.

    There are many posts about importing pics on the fly when you need to view them - but it doesn't get stored in Navision. They stay on a seperate drive or in your case sounds like you need a seperate Picture server that back's itself up.
    then map a drive to that server.

    You basically have a picture box - sourceexp = Picture

    OnAfterGetRecord()
    SETRANGE("No.");
    CLEAR(Picture);
    CALCFIELDS(Picture);
    IF EXISTS ('YourDrive:\YourDirectory\'+"No."+'.BMP')
    THEN Picture.IMPORT('YourDrive:\YourDirectory\'+"No."+'.BMP',FALSE);

    I would add another code OnModify of the table to insure the pic doesn't get saved.
    because the pic is in "picture" as you're viewing it. If a modify happens while it's there in mem - it will get saved.
    So you want to drop the ax on the save pf the pic by clearing the boolean.
    CLEAR(Picture);

    Hope that made sence - i'm a bit tired
  • garakgarak Member Posts: 3,263
    But doen't forgett. Storing Data in a BLOB field can bring you in trouble.
    Becasue NAV select ever the Lenght of the Blobfield if there is a blobfield in the database.
    SELECT *, DATALENGTH(BLOBFIELD) FROM "Databasename"."dbo"."COMPANY$Empoyee" 
      WHERE [CONDITION] order by [SORT ORDER]
    

    So, if you have datas in the BLOB field, the SQL server must run some internal operations to get this datas.
    And it's not sure, that these datas are in the same page area (read books online to get more infos about how the server stores the data [8k page, Block (8 Pages)]. The BLOB self is not in the page of the data self. If you use BLOBs the sql server only use 16Bytes for a "Link" to the BLOB pages self. So, the server must read all this pages.

    This you can see with the SQL profiler and with the indicator "Reads". And also doen't forget. Every one "READ" mean, that the sqlserver must read a 8k page. So if you have a Read of 25697, the server must load 25697 * 8K = 205576 KB = ~ 200MB in the RAM of the server! And Navision send ever a select *, DATALENGTH(BLOBFIELD)! Also if you open a card form, if you open a list form, if you run a report or if you post a record or read arecord during a process that contains BLOB fields.

    So, i'm sure you doesn't need this perfomance bottlenecks ;-)

    Store the images separate in the network and save in your dataabse only the UNC path and extension.
    So you can also use gif, jpg, png, bmp, pdf, etc and not only bmp and the database will not increase. In server 2008 there is a new "feature" for this. Here you can also say, that the BLOB should be stored in the network and if you make a backup of the database the sever also backup the BLOB files.

    If you really need the datas in the database, please doen't store this datas in the BLOB field of the "main" table (here employee). Use as "workaround" a table like: EmployeePictures with the PK field of the table employee and a BLOB field. In this table you sore the pictures. And only if you need to see the pictures you open a form / report that get this datas from this table. So all other "precesses" over the empoyee table doesn't read this table because u doesn't use it and you have no performance trouble ......

    It's only a idea but i'm sure it's better than storing the data directly in the "maintable".

    Regards
    Do you make it right, it works too!
Sign In or Register to comment.