rec_DocumentAttachment: Record "Document Attachment"; rec_DocumentAttachment2: Record "Document Attachment"; Base64CU: Codeunit "Base64 Convert"; Url: Text; Object1: JsonArray; JsonText: Text; Client: HttpClient; ResponseMessage: HttpResponseMessage; VarOutStream: OutStream; imagenameT: Text; base64T: Text; rec_TenantMedia: Record "Tenant Media"; begin Url := 'https://pure-earth-53603.herokuapp.com/variants'; if not client.Get(Url, responseMessage) then Error('The call to the web service failed.'); if not ResponseMessage.IsSuccessStatusCode then Error('The web service returned an error message:\\' + 'Status code: %1\' + 'Description: %2', ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase); ResponseMessage.Content.ReadAs(JsonText); jFileName := GetArrayElementAsObject(Object1, 0, 'err'); imagenameT := GetTokenAsText(jFileName, 'imagename', 'err'); base64T := GetTokenAsText(jFileName, 'imagebase64', 'err'); rec_DocumentAttachment.Init(); rec_DocumentAttachment."Table ID" := 5401; rec_DocumentAttachment."No." := imagenameT; rec_DocumentAttachment2.SetRange("Table ID", 5401); rec_DocumentAttachment2.SetRange("No.", imagenameT); if rec_DocumentAttachment2.FindLast() then begin rec_DocumentAttachment."Line No." := rec_DocumentAttachment2."Line No." + 1000; rec_DocumentAttachment.ID := rec_DocumentAttachment2.ID + 1; end; rec_DocumentAttachment."File Name" := imagenameT; rec_DocumentAttachment."Attached By" := '{9e089eeb-4e51-49ec-be35-0d203e241c49}'; rec_DocumentAttachment."Attached Date" := CurrentDateTime; rec_DocumentAttachment."File Type" := rec_DocumentAttachment."File Type"::Image; rec_DocumentAttachment."File Extension" := 'jpg'; rec_DocumentAttachment.VariantAttachment := true; rec_DocumentAttachment.Insert(); if rec_DocumentAttachment.FindLast() then; rec_TenantMedia.Init(); rec_TenantMedia.ID := CreateGuid(); rec_TenantMedia.Description := imagenameT; rec_TenantMedia."Mime Type" := 'image/jpeg'; rec_TenantMedia."Company Name" := COMPANYNAME; rec_TenantMedia."File Name" := imagenameT + '.jpg'; rec_TenantMedia.Height := 500; rec_TenantMedia.Width := 500; rec_TenantMedia.CalcFields(Content); rec_TenantMedia.Content.CreateOutStream(VarOutStream); Base64CU.FromBase64(base64T, VarOutStream); rec_TenantMedia.Insert(); end;