Skip to main content

Single Report Retrieval on Grid (Controller)

Codes used for the controller side

[HttpPost] 
[ActionName("GetReport")]
[NoRequestHeaders]
[NoResponseHeaders]
public GetReportResponse GetReport([FromBody] GetReportRequest body){
_EncryptedData = body. Session.EncryptedData;
_Language = body. Session.Language;
_Token = body. Session.Token;
ClientServices.DocumentManagementService dmInternalApiClient = null;
ServiceApiHelper serviceApiHelper = null;
string tokenId = "";
dmInternalApiClient = new ClientServices.DocumentManagementService(HttpClientConfiguration.InternalApiUrl);
tokenId = body. Session.TokenId;
MemoryStream publishedStream = new MemoryStream();
ExcelDocument document = new ExcelDocument();
var form = ServiceApi.FormManager.Create("ProjectName", "FormName", body. DocumentId). Result;
document. Items.AddText("-", form. Controls["-"]. Text.ToString());
document. Items.AddText("-", form. Controls["-"]. Text.ToString());
DownloadDataRequest downloadDataRequest = new DownloadDataRequest
{id = // id -```>``` file id
Parameters = Headers,
commitId = 0,
ForDownload = true,
IsBranch = false,
Path = "",
TokenId = tokenId,
Type = ObjectType.File,
VersionId = 0
};
Google.Protobuf.ByteString byteString = dmInternalApiClient.DownloadData(downloadDataRequest). Result.Result.Data; Stream stream = new MemoryStream(byteString.ToByteArray());
document. Build(stream). Wait();
document. Save(publishedStream, Bimser.Synergy.DocumentBuilder.Common.Enums.CellSaveFormat.Xlsx). Wait();
publishedStream.Position = 0;
UploadFileRequest uploadFileRequest = new UploadFileRequest
{ Data = Google.Protobuf.ByteString.FromStream(publishedStream),
Parameters = Headers,
MimeType = "application/xlsx",
FolderId = //FOLDERID -```>``` Folder Id
};
uploadFileRequest.Name.Add("en-US", $"{form. Controls["-"]. Text.ToString()}.xlsx");
UploadFile uploadFileResponse = dmInternalApiClient.UploadFile(uploadFileRequest). Result.Result;
return new GetReportResponse{SecretKey=uploadFileResponse.SecretKey,FileName=uploadFileResponse.Name[body. session.language],result=""};
}

Required methods

public class GetReportRequest{
public long DocumentId{get; set;}
public UserSession Session{get; set;}
public long ProcessId{get; set;}
public long ReportType{get; set;}
}
public class GetReportResponse{
public string SecretKey{get; set;}
public string FileName{get; set;}
public string Result{get; set;}
}

Codes used to download the report on the client side (Client)

const getReportRes:any= await this.fetch.post("/FormName/GetReport", 
{DocumentId: (Number)(args.targetArgs.row.data.DOCUMENTID),Session: this.session,ProcessId: args.targetArgs.row.data.ProcessID}); let downloadUrl = await this.fetch.post((window as any).serviceConfig.services.dm.baseURL +"/DocumentManagement/Objects/GetDownloadUrl", {secretKey: getReportRes.data.secretKey,fileName : getReportRes.data.fileName} ); const link = document.createElement('a'); link.target = "_blank";
link.href = (window as any).serviceConfig.services.dm.baseURL + "/" + (downloadUrl.data as any).downloadUrl;
link.setAttribute('download', getReportRes.data.fileName);
document.body.appendChild(link);
link.click();
console.log("initiating download");
document.body.removeChild(link);