Copy MediaSet from company to another company

LefteyedLefteyed Member Posts: 43
Hi guys

Anyone worked with MediaSet and transfer/Copy from one company to another?

I have a picture on Item that I want to copy to all companies. But cant use NewRec.Picture := OldRec.Picture
Any ideas?

Best Answers

  • LefteyedLefteyed Member Posts: 43
    edited 2017-10-18 Answer ✓
    After spending some time with those tables we found out that it is possible to use the same picture/media in different companies.

    Table 2000000184 Tenant Media
    Here the picture is saved in a blob field.
    There are also a company name. This name is the owner of the blob field. If we make the field empty then all companies are able to use then picture.

    Table 2000000183 Tenant Media Set
    It contains a record for every connection between for instance item and picture.
    Here the company must be changed so that the item and company is matching.
    When exporting picture from one item (company 1) and inserting it to another item (company 2) and we used item2.changecompany this was not enough.
    The record in this table sets the company name to be the same as item1.


    It seems to be an issue with NAV2017 CU3 with Item.Picture.Item(index) as it creates an error (Compiling af collection xxxxx. .dll failed)

    Therefore we didn't get it in the first place, but after trying with NAV2017 CU7 we got this working:

    Item2.Picture.INSERT(Item1.Picture.ITEM(1));
    Item2.MODIFY;
    TenantMedia.GET(Item1.Picture.ITEM(1));
    TenantMedia."Company Name" := '';
    TenantMedia.MODIFY;
    IF TenantMediaSet.GET(Item2.Picture.MEDIAID,Item1.Picture.ITEM(1)) THEN
    BEGIN
    TenantMediaSet."Company Name" := 'CRONUS Danmark';
    TenantMediaSet.MODIFY;
    END;


    EDIT:
    We had it working in CU7, but checked the list and in CU5 there is this:

    206147 The Mediaset Item function does not work.

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Have you tried CALCFIELDS + TRANSFERFIELDS ?
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • LefteyedLefteyed Member Posts: 43
    Calcfields is okay on BLOB, but as in NAV2017 and newer it is MediaSet and then it is not flowfield.
    Therefore CALCFIELDS is not allowed.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    I guess your answer is that the TRANSFERFIELDS also does not work.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • JuhlJuhl Member Posts: 724
    MediaSet is only a collection of Media.
    Media is stored in a separate table, where the blob is stored.

    I always create a Media type field, as MediaSet can’t clean up Media. So old files are left with no parent.

    You can stream Media in and out.
    Follow me on my blog juhl.blog
  • LefteyedLefteyed Member Posts: 43
    I was looking at page 31 as it has picture in a factbox where you can export the picture.

    "Funny" thing is that the code is like:

    ExportFile - OnAction()
    NameValueBuffer.DELETEALL;
    ExportPath := TEMPORARYPATH + "No." + FORMAT(Picture.MEDIAID);
    Picture.EXPORTFILE(ExportPath);
    FileManagement.GetServerDirectoryFilesList(TempNameValueBuffer,TEMPORARYPATH);
    TempNameValueBuffer.SETFILTER(Name,STRSUBSTNO('%1*',ExportPath));
    TempNameValueBuffer.FINDFIRST;
    ToFile := STRSUBSTNO('%1 %2.jpg',"No.",Description);
    DOWNLOAD(TempNameValueBuffer.Name,DownloadImageTxt,'','',ToFile);
    IF FileManagement.DeleteServerFile(TempNameValueBuffer.Name) THEN;


    So even as my picture is bmp, it will save it as jpg.

    I was also looking at MediaSet table and Media.
    But found out that the picture is saved in Table 2000000184 Tenant Media.

    It seems like that I need to save the picture 4 times due to 4 companies. There should be a smarter way of doing this. Save it ones, then make Ref to the picture. And if no ref to a picture, then it should be deleted.

  • JuhlJuhl Member Posts: 724
    Create a picture table with a Media field, make the table per database.
    Follow me on my blog juhl.blog
  • LefteyedLefteyed Member Posts: 43
    edited 2017-10-18 Answer ✓
    After spending some time with those tables we found out that it is possible to use the same picture/media in different companies.

    Table 2000000184 Tenant Media
    Here the picture is saved in a blob field.
    There are also a company name. This name is the owner of the blob field. If we make the field empty then all companies are able to use then picture.

    Table 2000000183 Tenant Media Set
    It contains a record for every connection between for instance item and picture.
    Here the company must be changed so that the item and company is matching.
    When exporting picture from one item (company 1) and inserting it to another item (company 2) and we used item2.changecompany this was not enough.
    The record in this table sets the company name to be the same as item1.


    It seems to be an issue with NAV2017 CU3 with Item.Picture.Item(index) as it creates an error (Compiling af collection xxxxx. .dll failed)

    Therefore we didn't get it in the first place, but after trying with NAV2017 CU7 we got this working:

    Item2.Picture.INSERT(Item1.Picture.ITEM(1));
    Item2.MODIFY;
    TenantMedia.GET(Item1.Picture.ITEM(1));
    TenantMedia."Company Name" := '';
    TenantMedia.MODIFY;
    IF TenantMediaSet.GET(Item2.Picture.MEDIAID,Item1.Picture.ITEM(1)) THEN
    BEGIN
    TenantMediaSet."Company Name" := 'CRONUS Danmark';
    TenantMediaSet.MODIFY;
    END;


    EDIT:
    We had it working in CU7, but checked the list and in CU5 there is this:

    206147 The Mediaset Item function does not work.
Sign In or Register to comment.