Options

How can I get blob value from one table to another in NAV 2016?

MauritsioMauritsio Member Posts: 27
Hi,

I have a blob field (memo, not compressed) in table1 having a value.

How can I get a blob value from table1 to table2 blob field in NAV 2016? Table2 blob field is having the same field number like in table1.

I have tried for instance several tricks like transferfields, calcfields, createinstream, createoutstream, copystream functions and so on.

If I for example execute calcfields for table1 blob field it empties a blob value from memory.

Pls give a short example how I can do that in NAV 2016 if you have any. Thanks in advance!

Best Answer

Answers

  • Options
    SilverXSilverX Member Posts: 134
    Hi Mauritsio,

    in fact you can simply assign one Blob to another.
    SomeTable."Some Blob" := TempBlob.Blob;
    
    Before using CALCFIELDS() on the source, make sure it is actually a record inside a recordset. If it is only an instance (not added to dataset through INSERT()/MODIFY()), do not use CALCFIELDS().
    Cheers
    Carsten


    ==> How To Ask Questions The Smart Way

    This post is my own opinion and does not necessarily reflect the opinion or view of my employer.
  • Options
    MauritsioMauritsio Member Posts: 27
    Hi SilverX,

    I tried to assign a blob value but it does not work.
    Table2.Blob2 := Table1.Blob1;
    

    Here's a code sample I used:
    WITH Table1 DO BEGIN
         Table2.INIT;
         Table2.TRANSFERFIELDS(Table1);
         Table2."No." := "No.";
         Table2.Blob2 := Blob1;
         Table2.INSERT;
    END;
    
  • Options
    da_nealda_neal Member Posts: 76
    edited 2017-03-16
    WITH Table1 DO BEGIN
         CALCFIELDS(Blob1);
         Table2.INIT;
         Table2.TRANSFERFIELDS(Table1);
         Table2."No." := "No.";
         Table2.Blob2 := Blob1;
         Table2.INSERT;
    END;
    
  • Options
    SilverXSilverX Member Posts: 134
    Please also take a look here: http://www.dynamics.is/?p=1267
    Cheers
    Carsten


    ==> How To Ask Questions The Smart Way

    This post is my own opinion and does not necessarily reflect the opinion or view of my employer.
  • Options
    MauritsioMauritsio Member Posts: 27
    da_neal: I tried you example and didn't work. Calcfields cleared a blob value.

    SilverX: I checked already a page you mentioned and tried with all code examples with no luck.
  • Options
    SilverXSilverX Member Posts: 134
    Please use the debugger and check the length property of source and destination Blob. Before and after assignment. I assume the source is empty.
    Cheers
    Carsten


    ==> How To Ask Questions The Smart Way

    This post is my own opinion and does not necessarily reflect the opinion or view of my employer.
  • Options
    HannesHolstHannesHolst Member Posts: 119
    Hi Mauritsio,

    Probably you have a problem somewhere else in the code.
    To check if your Blob-field has a value, use the following code:
    Table1.CALCFIELDS(Blob1);
    IF Table1.Blob1.HASVALUE THEN BEGIN
      Table2.INIT;
      Table2."No." := Table1."No.";
      Table2.Blob2 := Table1.Blob1;
      Table2.INSERT;
    END;
    
    Table2.CALCFIELDS(Blob2);
    MESSAGE('Blob value copied: ', Table2.Blob2.HASVALUE);
    

    If you don't get a 'Yes' in the end, the problem is somewhere else.
    Good luck.

  • Options
    MauritsioMauritsio Member Posts: 27
    SilverX: I checked lenthg of source and destination from debugger before and after assignment
    -> Source has value all the time but the destination doesn't.

    HannesHolst: First CALCFIELDS for Blob1 clears the value of Blob1. If I run the code without calcfield for blob1 field, it has value all the time but blob2 does'nt even if calcfields are executed for blob2 after insert.
  • Options
    da_nealda_neal Member Posts: 76
    May be you have 2 variable Table1 (check local - global)?
  • Options
    HannesHolstHannesHolst Member Posts: 119
    @Mauritsio
    You have to reveal the truth and post your actual code :-)

    CALCFIELDS for a Blob is OK.
    It's used by NAV-standard also. Check the screenshot.

    8qy1lvj1fodm.png
  • Options
    MauritsioMauritsio Member Posts: 27
    Okay :smile: Here's my one try. My added code marked as yellow -> Codeunit5988

    Calcfields empties blobfield InternalMsg. My intention is to assign InternalMsg blob field value from Service Header to Service Shipment Header that will end up to database table in INSERT.

    gkyeufurnacw.jpg


  • Options
    MauritsioMauritsio Member Posts: 27
    Thanks HannesHolst! PrepareShipmentHeader Function was not correct place for assigning blob to blob field since as you mentioned there were temporary rec variables used for collecting data into temporary record.

    Instead, I added my code to CU5899 to funtion FinalizeShipmentDocument where the actual insert is done into Service Shipment Header table with rec variable PServShptHeader and it now works nicely.

    3lt3zjgpv3s6.png
Sign In or Register to comment.