Skip to main content

I am trying to render a report and then email it. It is created two ways, one on demand and the other in the background. Both methods work fine on my test instance, however in production the background method almost always returns an empty report. My assumption is that the report is missing a context or there is some race condition, but I am not sure.

To be clear the report is generated, with a title and other fixed fields populated, however with zero data fields populated.

The background method is kicked off by a business event, I do have some PXTrace statements in my functions, however they don’t seem to produce results when the function is called from a business event, is this normal? The PXTrace is visible in the profiler when the action is executed by button press.

Below is the function that creates the report, uploads it and then attaches it to the email.

Any direction would be helpful at this point I have tried a lot of different things.

        protected static void _addTaskOrders(PXGraph graph, PMTask task, CREmailActivityMaint emailMaint, CRSMEmail email, IReportLoaderService reportLoader, IReportRenderer reportRenderer, bool noCost)
{
var prj = PMProject.PK.Find(graph, task.ProjectID);

PXTrace.WriteInformation($"Prj {prj.ContractCD} Tsk {task.TaskCD}");

Dictionary<String, String> parameters = new Dictionary<String, String>();
// parameters.Add("TaskID", task.TaskID.ToString());
parameters.Add("Project", prj.ContractCD.Trim());
parameters.Add("Task", task.TaskCD.Trim());
parameters.Add("View", noCost ? "No Cost" : "Internal");// Internal");

Report _report = reportLoader.LoadReport("GP603010", null);
reportLoader.InitDefaultReportParameters(_report, parameters);

bytey] fileData;

using (StreamManager streamMgr = new StreamManager())
{
reportRenderer.Render(RenderType.FilterPdf, _report, deviceInfo: null, streamMgr);
fileData = streamMgr.MainStream.GetBytes();
}

var fileName = $"{prj.ContractCD} - {task.TaskCD.Trim()}.pdf";
var fileInfo = new PX.SM.FileInfo(Guid.NewGuid(), fileName, null, fileData);
// Save file to database
var uploadFileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileGraph.SaveFile(fileInfo, FileExistsAction.CreateVersion);

// Attach file to the dedicated table
PXNoteAttribute.SetFileNotes(emailMaint.Cacheshtypeof(CRSMEmail)], email, fileInfo.UID.Value);
uploadFileGraph.Persist();
}

 

Is there any restriction group you set for your site?


No group restrictions.


Hi @Leif were you able to find a solution? Thank you!


Reply