Media or Mediaset how to access a mediaset dynamically
Sog
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?
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?
0
Best 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.0
Answers
-
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.0 -
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions