RE: How to handle server methods in D365
It's hard to tell where it got an error without going into debug. Below, I commented on 4 points in the code where it throw errors. Of course, the method may throw errors from other methods that it calls.
public void renderTemplateToStream(DocuTemplate template, Map filtersToApply, System.IO.Stream outputStream, object context = null)
{
//1.Wrong parameters specified
//template and outputStream must be full.
//If you are getting this error, either the code could not find the record in DocuTemplate,
//or it is not authorized to read the object to be thrown into the Stream
//(it may not find the object too)
//
if (!template || !outputStream)
{
throw error(error::missingParameter(null));
}
if (!filtersToApply)
{
filtersToApply = new Map(Types::String, Types::Class);
}
//2.Function renderTemplateToStream has been incorrectly called.
//I don't think the error is from here
else if (filtersToApply.keyType() != Types::String || filtersToApply.valueType() != Types::Class)
{
throw error(error::wrongUseOfFunction(methodStr(DocuTemplateRender, renderTemplateToStream)));
}
//3.Function renderTemplateToStream has been incorrectly called.
// CanWrite Property indicates whether the current stream supports writing.
if (!outputStream.CanWrite)
{
throw error(error::wrongUseOfFunction(methodStr(DocuTemplateRender, renderTemplateToStream)));
}
var filtersByPublicName = this.translateFilterMap(filtersToApply);
switch (template.TemplateType)
{
case OfficeAppApplicationType::Excel:
this.renderExcelTemplate(template, filtersByPublicName, outputStream, context);
break;
case OfficeAppApplicationType::Word:
this.renderWordTemplate(template, filtersByPublicName, outputStream, context);
break;
default:
//4.Finally the type should be Excel or word
var ex = new System.NotImplementedException();
throw error(ex.Message);
}
}