Options

How to use the ODataV4 web service to get the item picture in Visual Studio 2017

Hi guys,

May I know how to use the ODataV4 web service to get the item image/picture in Visual Studio 2017?

Any expert can help me on this or provide me the sample? I had installed the OData v4 client code generator also but still cannot get it.

Thank you.

Answers

  • Options
    foo_barfoo_bar Member Posts: 91
    What version of NAV are you using?
    If you could use the API endpoints instead of OData, then look at this: https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/api/dynamics_item_get_picture

    If you have to use OData, then the easiest solution is adding a field to your OData page, and display the image as a Base64 string (imo)
  • Options
    xavierho970304xavierho970304 Member Posts: 12
    foo_bar wrote: »
    What version of NAV are you using?
    If you could use the API endpoints instead of OData, then look at this: https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/api/dynamics_item_get_picture

    If you have to use OData, then the easiest solution is adding a field to your OData page, and display the image as a Base64 string (imo)

    I using BC version 16, do you mean I need to create a new field to get the image as a Base64 string right? May I know do you have any example for this? It is because I know if direct use the SOAP or OData cannot get the url/data from my original item image field
  • Options
    foo_barfoo_bar Member Posts: 91
    edited 2020-08-25
    See following code for a simple example using OData.
    Let me know if something is not clear
    page 50000 "OData Item"
    {
        PageType = List;
        ApplicationArea = All;
        UsageCategory = Lists;
        SourceTable = Item;
    
        layout
        {
            area(Content)
            {
                repeater(GroupName)
                {
                    field("No."; "No.")
                    {
                        ApplicationArea = All;
                    }
                    field(Base64Gbl; Base64Gbl)
                    {
                        ApplicationArea = All;
                    }
                }
            }
        }
    
        var
            Base64Gbl: Text;
    
        trigger OnAfterGetRecord()
        var
            TenantMediaLcl: Record "Tenant Media";
            ConvertMgmtLcl: Codeunit "Base64 Convert";
            InStreamLcl: InStream;
        begin
            Base64Gbl := '';
            if Rec.Picture.Count > 0 then
                if TenantMediaLcl.Get(Rec.Picture.Item(1)) then begin
                    TenantMediaLcl.CalcFields(Content);
                    TenantMediaLcl.Content.CreateInStream(InStreamLcl);
                    Base64Gbl := ConvertMgmtLcl.ToBase64(InStreamLcl);
                end;
        end;
    }
    

    z5azziw80vvu.png
Sign In or Register to comment.