Dear all,
I am generating a word template using data entity in my code and uploading/inserting to standard attchments for that particular record using x . The said process executes when clicking a button in the form. the button doesnt have any restrictions for role.
I am facing the mentioned error when using custom roles, but my code is working for system admin role.
Any suggestions plzzz.
the code used is attached below.
<>
DocuTemplate template = DocuTemplate::findTemplate(OfficeAppApplicationType::Word,templateName);
extension = strReverse(subStr(strReverse(template.FileName), 1, strFind(strReverse(template.FileName),'.',1,strLen(template.FileName))));
fileName = strReverse(subStr(strReverse(template.FileName),6,strlen(template.FileName)));
fileNameOrig = strfmt('%1%2',contractTable.ContractID,Extension);
// Ensure the template was present.
if (template && template.TemplateID == templateName)
{
Map filtersToApply = new Map(Types::String, Types::Class);
// Create vendors filter
ExportToExcelFilterTreeBuilder filterBuilder = new ExportToExcelFilterTreeBuilder(template.RootEntityName);
anytype filterString = filterBuilder.areEqual(fieldstr(CMSContractDocumentTemplateTmpEntity, ContractId), contractTable.contractId);
filtersToApply.insert(tablestr(CMSContractDocumentTemplateTmpEntity), filterString);
// generate the workbook using the template and filters
DocuTemplateRender renderer = new DocuTemplateRender();
ExportToExcelStorageHelper storagehelper = new ExportToExcelStorageHelper();
//sheik written
System.IO.MemoryStream filestreem = new System.IO.MemoryStream();
renderer.renderTemplateToStream(template,filtersToApply,filestreem);
filestreem.Seek(0, System.IO.SeekOrigin::Begin);
DocumentManagement::attachFile(contractTable.TableId, contractTable.RecId, contractTable.DataAreaId,fileType.TypeId, filestreem, fileNameOrig, classstr (FileUploadTemporaryStorageStrategy), contractTable.ContractID);