Как изменить имя скачиваемого файла печатной формы?(пример того что нашел внутри)
Я нашел метод , который вызывает при скачивании отчета, проблема состоит в том, что caption, который я передаю в него не работает, отчет всегда скачивается с именем печатной формы, а не моим кастомным, хотя аттрибут download верный, не пойму в чем проблема, подскажите
При это когда ставишь брейк поинт , видно что параметр caption в функцию подается именно мой
/**
* Downloads the report.
* @protected
* @param {String} caption Caption.
* @param {String} key Report key.
*/
downloadReport: function(caption, key) {
var report = document.createElement("a");
report.href = "../rest/ReportService/GetReportFile/" + key;
report.download = caption;
if (this.Ext.isIE) {
report.target = "_blank";
}
document.body.appendChild(report);
report.click();
document.body.removeChild(report);
}
Нравится
Такой подход не работает, тоже когда-то пробовал передачу caption. Удалось это достичь замещением класса ReportHelper и метода CreateReport в нем. Вот мой пример:
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text.RegularExpressions;
using System.Web;
using Terrasoft.Common;
using Terrasoft.Core;
using Terrasoft.Core.Factories;
using Terrasoft.Reports;
using System.Web.Script.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Terrasoft.Configuration.ReportService
{
public class AdditionalReportDetails
{
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
}
[Terrasoft.Core.Factories.Override]
class UsrReportHelper : ReportHelper
{
public override string CreateReport(string entitySchemaUId, string reportSchemaUId, string templateId, string recordId,
string reportParameters, bool convertInPDF)
{
string newName ="";
var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];
string key = string.Format("ReportCacheKey_{0}", Guid.NewGuid());
ReportData data = new ReportData();
bool shouldModifyCaption = string.IsNullOrEmpty(reportParameters);
if (!shouldModifyCaption)
{
AdditionalReportDetails result = JsonSerializer.Deserialize<AdditionalReportDetails>(reportParameters, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
newName = " " + result.Email + " " + result.Id;
}
ReportService reportService = new ReportService();
data = reportService.GenerateMSWordReport(templateId, recordId, convertInPDF);
if (!String.IsNullOrEmpty(newName))
{
data.Caption += newName;
}
userConnection.SessionData[key] = data;
return key;
}
}
}А для него в схеме ContactSectionV2 еще сделал замещение метода getMsWordPrintFormConfig:
define("ContactSectionV2", [],
function() {
return {
entitySchemaName: "Contact",
diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
methods: {
getMsWordPrintFormConfig: function(printForm) {
const recordIds = !this.get("MultiSelect") ? [this.getPrintRecordId()] : this.getSelectedItems();
const convertInPdf = printForm.get("ConvertInPDF");
const useNewPdfGeneration = convertInPdf && Terrasoft.Features.getIsEnabled("AsyncPdfReportGeneration");
var currentRecordValues = this.getActiveRow().values;
var valuesToPass = {
email: currentRecordValues.Email,
id: currentRecordValues.Id,
};
var reportParams = JSON.stringify(valuesToPass);
return {
serviceRequest: {
serviceName: useNewPdfGeneration ? "PdfAsyncReportGenerationController" : "ReportService",
methodName: useNewPdfGeneration ? "CreateReports" : "CreateReportsList",
data: {
templateId: printForm.getTemplateId(),
recordIds: recordIds,
convertInPDF: convertInPdf,
reportParameters: reportParams
},
timeout: this.reportDownloadTimeout
},
callback: useNewPdfGeneration ? this._asyncGenerationCallback : function(response) {
Terrasoft.each(response.CreateReportsListResult, function(key) {
this.downloadReport(printForm.getCaption(), key);
}, this);
}
};
},
},
};
});Задумка была в формировании заголовка для отчета как название отчета + email контакта + Id контакта. Результат был такой:
Надеюсь этот пример поможет.
Решил замещением метода CreateReport из Terrasoft.Configuration.ReportService
Такой подход не работает, тоже когда-то пробовал передачу caption. Удалось это достичь замещением класса ReportHelper и метода CreateReport в нем. Вот мой пример:
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text.RegularExpressions;
using System.Web;
using Terrasoft.Common;
using Terrasoft.Core;
using Terrasoft.Core.Factories;
using Terrasoft.Reports;
using System.Web.Script.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Terrasoft.Configuration.ReportService
{
public class AdditionalReportDetails
{
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
}
[Terrasoft.Core.Factories.Override]
class UsrReportHelper : ReportHelper
{
public override string CreateReport(string entitySchemaUId, string reportSchemaUId, string templateId, string recordId,
string reportParameters, bool convertInPDF)
{
string newName ="";
var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];
string key = string.Format("ReportCacheKey_{0}", Guid.NewGuid());
ReportData data = new ReportData();
bool shouldModifyCaption = string.IsNullOrEmpty(reportParameters);
if (!shouldModifyCaption)
{
AdditionalReportDetails result = JsonSerializer.Deserialize<AdditionalReportDetails>(reportParameters, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
newName = " " + result.Email + " " + result.Id;
}
ReportService reportService = new ReportService();
data = reportService.GenerateMSWordReport(templateId, recordId, convertInPDF);
if (!String.IsNullOrEmpty(newName))
{
data.Caption += newName;
}
userConnection.SessionData[key] = data;
return key;
}
}
}А для него в схеме ContactSectionV2 еще сделал замещение метода getMsWordPrintFormConfig:
define("ContactSectionV2", [],
function() {
return {
entitySchemaName: "Contact",
diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
methods: {
getMsWordPrintFormConfig: function(printForm) {
const recordIds = !this.get("MultiSelect") ? [this.getPrintRecordId()] : this.getSelectedItems();
const convertInPdf = printForm.get("ConvertInPDF");
const useNewPdfGeneration = convertInPdf && Terrasoft.Features.getIsEnabled("AsyncPdfReportGeneration");
var currentRecordValues = this.getActiveRow().values;
var valuesToPass = {
email: currentRecordValues.Email,
id: currentRecordValues.Id,
};
var reportParams = JSON.stringify(valuesToPass);
return {
serviceRequest: {
serviceName: useNewPdfGeneration ? "PdfAsyncReportGenerationController" : "ReportService",
methodName: useNewPdfGeneration ? "CreateReports" : "CreateReportsList",
data: {
templateId: printForm.getTemplateId(),
recordIds: recordIds,
convertInPDF: convertInPdf,
reportParameters: reportParams
},
timeout: this.reportDownloadTimeout
},
callback: useNewPdfGeneration ? this._asyncGenerationCallback : function(response) {
Terrasoft.each(response.CreateReportsListResult, function(key) {
this.downloadReport(printForm.getCaption(), key);
}, this);
}
};
},
},
};
});Задумка была в формировании заголовка для отчета как название отчета + email контакта + Id контакта. Результат был такой:
Надеюсь этот пример поможет.