I have been working in project that create a folder through Business Central when you click on an Action. It's working fine, but now I wanted to when I click in the Action it send the Report, in Page Item Card(30), to my folder in the Sharepoint. I created a procedure to do that, but the problem its when I try to open the Report(PDF) on Sharepoint, it says "looks like the file don't have a preview we can show you." Here is the procedure that Im using.
procedure UploadFile(AccessToken: Text; Url: Text; Item: Record Item): Boolean
var
Client: HttpClient;
Headers: HttpHeaders;
RequestMessage: HttpRequestMessage;
ResponseMessage: HttpResponseMessage;
RequestContent: HttpContent;
ResponseText: Text;
IsSucces: Boolean;
Item_Vendor_Catalog: Report "Item/Vendor Catalog";
ItemVendor: Record "Item Vendor";
Json1: JsonObject;
out: OutStream;
ins: InStream;
RecRef: RecordRef;
TempBlob_lRec: Codeunit "Temp Blob";
FileManagement_lCdu: Codeunit "File Management";
Base64: Codeunit "Base64 Convert";
begin
Headers := Client.DefaultRequestHeaders();
Headers.Add('Authorization', StrSubstNo('Bearer %1', AccessToken));
Headers.Add('Accept', 'application/json;odata=nometadata');
ItemVendor.Get(Item."Vendor No.", Item."No.");
Item_Vendor_Catalog.SetTableView(ItemVendor);
RequestMessage.SetRequestUri(Url);
RequestMessage.Method('POST');
TempBlob_lRec.CreateOutStream(out, TEXTENCODING::UTF8);
RecRef.Get(ItemVendor.RecordId);
Report.SaveAs(Report::"Item/Vendor Catalog", '', ReportFormat::Pdf, out);
TempBlob_lRec.CreateInStream(ins, TEXTENCODING::UTF8);
// ins.Read(out);
// Message(Base64.ToBase64(ins));
// Message('out ' + Format(out));
// Message('ins ' + Format(ins));
System.CopyStream(out, ins);
RequestContent.WriteFrom(ins);
RequestMessage.Content(RequestContent);
if Client.Send(RequestMessage, ResponseMessage) then
if ResponseMessage.IsSuccessStatusCode() then begin
if ResponseMessage.Content.ReadAs(ResponseText) then
IsSucces := true;
end else
ResponseMessage.Content.ReadAs(ResponseText);
end;
I don't think your report is actually getting generated. I would add a variable
Parameters: Text
and make the following changesYou can remove this line of code
RecRef.Get(ItemVendor.RecordId);
and I think it should work.