Media or Mediaset how to access a mediaset dynamically

SogSog Member Posts: 1,023
Hi everybody.
In NAV Madeira/2017 we get a new datatype mediaset. All in all an interesting setup for images, but I'm unable to access them dynamically. Currently the only option is record.media(set)field.MEDIAID to retrieve the related GUID of the field, so you can subsequently retrieve the blob value and/or stream from the Tenant Media system table. However when using recordrefs/fieldrefs the fieldref.value contains an empty guid, and calcfields is denied since it's not a flowfield.
In the description in the table Tenant Media, you do see what could be something as a recordid (without the table prefix). But this is anything but robust.

Anybody willing to share their results of research on the new media/mediaset datatypes?
|Pressing F1 is so much faster than opening your browser|
|To-Increase|

Best Answer

  • SogSog Member Posts: 1,023
    Answer ✓
    Ok, I finally found out why I got empty an empty guid when calling fieldref.value on a mediaset. I got the recordreference from a recordID. Now when I do recordref.GET(recordID), I get the mediaset GUID. However (and this was my problem). when you set the recordreference like this: recordreference := recordID.GETRECORD, the fieldreference shows an empty GUID. I'll post an example when I finished my work, but I thought I'd share this anyway.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|

Answers

  • nhsejthnhsejth Member, Microsoft Employee Posts: 34
    Hi,

    Please notice that you actually have two new types, Media and MediaSet, where the latter is treated as a collection of media items. The types are only supported as table fields (like the old blob type) and are intended to store images used by the client. As the media objects are treated an immutable objects, the use of direct access to the system tables is strongly discouraged and may be limited in the future (and the schema can change). That's also why the standard permissions don't give users access to the tables. Access to the data will be by the API on the fieldtype and the API will evolve as the usage scenarios extends.

    I have included a small example (below) that can illustrate the use of media. The sample file contains a small table that uses the new types, a codeunit to import data and a page to display the content in the WEBCLIENT using the brick view (which currently only show the first media or mediaset field on the page). To make it work, you have to modify the file paths in the codeunit to point to sample images available on the local system.
    I used the codeunit to show, that the fieldref contains that id of the object stored in the record field. The ID that is returned from the mediaset is not the id of the media, stored in the set, but the set itself.
    You can find more in MSDN at https://msdn.microsoft.com/en-us/dynamics-nav/working-with-media-on-records.
    The Description field you see in the Media table is intended to hold a textual description of the image that a client can use to as a picture caption. This field is reserved for later use.
    The sample is provided as is and is just something I put together in a couple of minutes, so please don't use it for anything else but showcasing the questions in the first post.

    Paste the following into a text file and import in the development environment:

    OBJECT Table 55123 Media Test Table
    {
    OBJECT-PROPERTIES
    {
    Date=;
    Time=;
    Version List=;
    }
    PROPERTIES
    {
    }
    FIELDS
    {
    { 1 ; ;keyValue ;Integer }
    { 2 ; ;MediaField ;Media }
    { 3 ; ;MediaSetField ;MediaSet }
    }
    KEYS
    {
    { ;keyValue ;Clustered=Yes }
    }
    FIELDGROUPS
    {
    }
    CODE
    {

    BEGIN
    END.
    }
    }

    OBJECT Codeunit 55123 TestMedia
    {
    OBJECT-PROPERTIES
    {
    Date=;
    Time=;
    Version List=;
    }
    PROPERTIES
    {
    OnRun=VAR
    MediaTestTable@1000 : Record 55123;
    MediaTestTableRef@1001 : RecordRef;
    fieldRef@1002 : FieldRef;
    id@1003 : GUID;
    idSet@1004 : GUID;
    BEGIN
    MediaTestTable.DELETEALL;
    MediaTestTable.INIT;
    MediaTestTable.keyValue := 1;
    id := MediaTestTable.MediaField.IMPORTFILE('C:\Temp\media\Image1.jpg','Image1');
    idSet := MediaTestTable.MediaSetField.IMPORTFILE('C:\Temp\media\Image2.jpg','Image2');
    idSet := MediaTestTable.MediaSetField.IMPORTFILE('C:\Temp\media\Image3.jpg','Image3');
    MediaTestTable.INSERT;
    COMMIT;

    MediaTestTableRef.OPEN(55123);
    MediaTestTableRef.FINDFIRST;
    fieldRef := MediaTestTableRef.FIELD(MediaTestTable.FIELDNO(MediaField));
    MESSAGE('Field value should be %1, is %2', id, fieldRef.VALUE);

    fieldRef := MediaTestTableRef.FIELD(MediaTestTable.FIELDNO(MediaSetField));
    MESSAGE('Field value should be %1, is %2', idSet, fieldRef.VALUE);
    END;

    }
    CODE
    {

    BEGIN
    END.
    }
    }

    OBJECT Page 55123 TestMedia
    {
    OBJECT-PROPERTIES
    {
    Date=;
    Time=;
    Version List=;
    }
    PROPERTIES
    {
    SourceTable=Table55123;
    PageType=List;
    }
    CONTROLS
    {
    { 1 ;0 ;Container ;
    ContainerType=ContentArea }

    { 2 ;1 ;Group ;
    Name=Group;
    GroupType=Repeater }

    { 3 ;2 ;Field ;
    SourceExpr=keyValue }

    { 4 ;2 ;Field ;
    SourceExpr=MediaField }

    { 5 ;2 ;Field ;
    SourceExpr=MediaSetField }

    }
    CODE
    {

    BEGIN
    END.
    }
    }

    _________________
    Niels-Henrik Sejthen
    Senior Software Developer
    Microsoft Dynamics NAV

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • SogSog Member Posts: 1,023
    Answer ✓
    Ok, I finally found out why I got empty an empty guid when calling fieldref.value on a mediaset. I got the recordreference from a recordID. Now when I do recordref.GET(recordID), I get the mediaset GUID. However (and this was my problem). when you set the recordreference like this: recordreference := recordID.GETRECORD, the fieldreference shows an empty GUID. I'll post an example when I finished my work, but I thought I'd share this anyway.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
Sign In or Register to comment.