The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
IMPORTFILE Method (MediaSet)
Adds a media, such as a JPEG image, to the MediaSet data type field of a record for displaying the media in the client. The media is imported to the database and included in a MediaSet for the record.
[Guid := ]Record.MediaSetField.IMPORTFILE(FileName, Description[, MimeType])
Specifies the record that you want to add the media to.
Specifies the field that you want to add the media to. The field must have the MediaSet data type.
Specifies the full path and name of the media file to be imported.
Specifies text that can be used in the client to describe the media.
Specifies the media content type. MIME type is used by browsers, and is an Internet standard to describe the contents of a file. The MimeType value must be a two-part string that consists of a type and subtype, such as image/jpeg or image/gif. For more information, see Supported Media Types.
If this parameter is not specified, the function will deduct the MIME type from the file extension. For example the MIME type for a .jpg file is image/jpeg.
Property Value/Return Value
Specifies the unique ID that is assigned to the MediaSet of the record. You can also get this ID by using the MEDIAID Method (MediaSet).
You use this method to upload a media file as part of a collection of media objects that you want to associate with a record. The method is similar to the IMPORTFILE Method (Media) except that this method enables you to import multiple media files for the same record. For example, you can add multiple images for an item in table 27 Item.
When a media file is imported, a media object is created and stored in the system table 2000000181 Tenant Media of the application database. The media object is assigned a unique identifier (GUID).
In addition, the media object is assigned to a MediaSet which also has a specific GUID. This GUID is included in the MediaSet data type field as a reference to the media objects. The MediaSet and its GUID are created with the first media that is imported, and the information is stored in table 2000000183 Tenant Media Set. All additional media objects for the record are then associated with the same MediaSet GUID.
This example uses the IMPORTFILE method to add images to records in table 27 Item of the CRONUS demonstration database.
In support of the example code, you alsmust complete these tasks:
Create two sample image files that you want to use on item no. 1000 in table 27 Item.
Save the images as JPEG type, and give them the names 1000-v1.jpg and 1000-v2.jpg. Save the files in the C:\images folder on the computer that is running Dynamics 365 for Financials service instance.
Verify that table 27 Item has a field that is called Picture and has the data type MediaSet.
This is field on which you will add the images. If the field is not present, then add it.
With these tasks in place, you can add the following AL code for importing the images. For this code example, create a codeunit, and add the code to the OnRun trigger.
The code requires that you create the following variables and text constant:
|Text constant name||ConstValue|
|Text000||The files have been imported. Item %1 has %2 pictures in MediaSet: %3|
itemRec.GET('1000'); itemRec.Picture.IMPORTFILE('C:\images\1000-v1.jpg', 'Demo image for item ' + FORMAT(itemRec."No.")); itemRec.Picture.IMPORTFILE('C:\images\1000-v2.jpg', 'Demo image for item ' + FORMAT(itemRec."No.")); count := (itemRec.Picture.COUNT); mediasetId := itemRec.Picture.MEDIAID; MESSAGE(Text000,itemRec."No.", count, mediasetId);
If you run system table 2000000181 Tenant Media, you should see the new images in the list.