Importing picture to BLOB field

NagiNagi Member Posts: 151
Hi,

I'm trying to create a BLOB field where I want to upload a picture. I have a field type BLOB with the subtype property set to BitMap. There is no C/AL code in the field. Next, I have a form where I've copied the menu items pertaining to the Picture button on the Company Information form. I can't find any other C/AL code that needs to be copied, other than the code in the OnPush trigger to Import, Export, and Delete. With only minor alterations to the code, my code looks like this:
<Control1101101024> - OnPush()   //IMPORT

SignatureExists := Signature.HASVALUE;
IF Signature.IMPORT('*.BMP',TRUE) = '' THEN
  EXIT;
IF SignatureExists THEN
  IF NOT CONFIRM(Text001,FALSE) THEN
    EXIT;
CurrForm.SAVERECORD;

<Control1101101025> - OnPush()   //EXPORT

IF Signature.HASVALUE THEN
  Signature.EXPORT('*.BMP',TRUE)
ELSE
  MESSAGE(Text003);

<Control1101101026> - OnPush()   //DELETE 

IF Signature.HASVALUE THEN BEGIN
  IF CONFIRM(Text002,FALSE) THEN BEGIN
    CLEAR(Signature);
    CurrForm.SAVERECORD;
  END;
END ELSE BEGIN
  MESSAGE(Text004);
END;

SignatureExists is a variable of type Boolean (similar to PictureExists in the Company Information form) and Signature is the BLOB field.

For some reason, this doesn't work. I can't import the picture. There is no error message of any kind, but the picture just isn't imported to the record. I've tried importing the picture in the Company Information form, just to make sure that the picture matches any given criteria allowing it to be imported, and it worked fine.

If anybody has any suggestions on this, I would be very grateful.

Cheers!

Answers

  • kinekine Member Posts: 12,562
    Ok, I will take it from other side. Why do you thing, that the file is not imported? How you are testing it?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • NagiNagi Member Posts: 151
    I've tried running the debugger, and it runs through the code without any interruptions. Not having done this before, I thought maybe I had to use an InStream to write to the BLOB field, but I can't find examples of it being done this way in Nav. The only C/AL code I've been able to find, is what I've copied. Therefore, I'm quite puzzled as to why this doesn't work. ](*,)
  • AlishaAlisha Member Posts: 217
    Again.. how are you testing it?

    If you are showing the picture in a report for example, you have to do CALCFIELDS before, or it won't show...
  • NagiNagi Member Posts: 151
    Yes, I'm using CALCFIELDS(Signature) in an OnPreSection trigger on a report. I also tried adding a text box on the form and tie it to the field, just to see if the picture would be displayed, but nothing shows.
  • AlishaAlisha Member Posts: 217
    The control box must be a Picture Box, not a text box, and it's better to do the calcfields in the OnAfterGetRecord trigger, not in the Presection, because if you are showing a hader, it might not display anything, since in the header the record is still not accesible...
  • NagiNagi Member Posts: 151
    The control box must be a Picture Box
    #-o

    But still no picture.. The CALCFIELDS(Signature) is in the OnPreSection trigger in a footer section, but I've also tried it in the AfterGetRecord trigger.

    I've also tried exporting the picture after importing it, with the C/AL code set up to deliver a message if there is no picture to export. When I try exporting the picture, the C/AL code returns this message.
    IF Signature.HASVALUE THEN
      Signature.EXPORT('*.BMP',TRUE)
    ELSE
      MESSAGE(Text003);
    

    What am I not seeing? ](*,) ](*,) ](*,)

    Thanks for the help so far, though. Always appreciated. =D>
  • kinekine Member Posts: 12,562
    If there is value inthe BLOB field, you will see asterisk in the field when you run the table directly. If there are no data imported, it seems that they are not saved when the record is saved. Check if another code is called when the record is modified (like some code in OnModify of the table). May be that the code will clear the field.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • NagiNagi Member Posts: 151
    I figured it out! \:D/

    In case anybody else happens upon the same problem, the solution was to use CALCFIELDS(Signature) in the OnPush trigger before trying to export/delete the picture. I suppose this is necessary because the table I have the BLOB field in has multiple records, and Company Information, where the code was copied from, does not. Same problem with the picture box. On a tabular form, you have to use CALCFIELDS in the AfterGetRecord trigger to load the picture. This doesn't seem to be necessary on a card-type form though.

    So after changing text box -> picture box and adding CALCFIELDS in all the right places, it works :D

    Thanks for all the help! =D> =D> =D>
  • kinekine Member Posts: 12,562
    The calcfield in tabular form is needed to prevent calculation for all records when they are not needed. On the card form, you have just one record, it is not problem to call the calcfields automatically.. :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    also perhaps you don't know where your exporting

    IF Signature.HASVALUE
         THEN
         Signature.EXPORT('c:\signature.BMP',FALSE);
    
Sign In or Register to comment.