Reputation: 1369
I am working on setting up email templates in AX 2009 which would be sent out automatically to our customers when certain documents are posted. I have a framework in place that allows me to tie a specific posted document to a specific email template.
Currently, in order to have the information in the email dynamically populated, I am using a mapping object that holds key/value pairs, where the key relates to a specific variable in the template itself (see the sample in the question Dynamics Ax 2009, Email Templates). However, since I can very easily see the information that needs to be available changing significantly, I want to be able to change this mapping without having to change the actual code in the class.
My thought is to have a simple table, which contains two string fields - one would be the key in the mapping and the other would be the string representation of where the information is found, ie "salesTable.SalesId"
.
Is it possible to evaluate the value string expression so it would automatically pull "SO-XXXXXXXX"? In this case, we can assume that the salesTable buffer already exists at the point of evaluation. This would be similar to the Javascript eval()
command. It should also (ideally) evaluate more complex expressions, such as "CustTable::find(salesTable.InvoiceAccount).CustGroup"
, but at this point that may be too much to ask for.
The only other alternative I can see would be creating a giant mapping object that would contain all possible mappings and use that throughout the framework, but that still runs the risk of not having all the information that may be needed in a template, so would require additional code changes to get the missing information in.
Upvotes: 0
Views: 1799
Reputation: 11544
Is it possible to evaluate the value string expression so it would automatically pull "SO-XXXXXXXX"?
Not without custom code. The base framework \Data Dictionary\Tables\SysEmailTable\Methods\sendMail
handles key/value mappings and XML data.
You should also be careful because evaluating those expressions could potentially circumvent AX security and allow users to see data they shouldn't be able to and/or execute custom code.
You're planning for a scenario that may happen less than you think, but if you really want a solution, I have a few ideas.
You could systematically build a large mapping by crawling over a few tables you may need (SalesTable, CustTable) using the SysDictTable/SysDictField object and that would provide you a pretty easy solution. Here is a sample proof of concept job that would accept a "_common" parameter and build your map. You can see another place where this similar style is used here: (\Classes\BIGenerator\record2DataSetXml
)
static void Job33(Args _args) {
SysDictTable sysDictTable;
SysDictField sysDictField;
SalesTable salesTable;
Common _common;
int i;
Map map = new Map(Types::String, Types::String);
str value;
FieldId fieldId;
MapEnumerator me;
;
select firstonly salesTable;
_common = salesTable;
sysDictTable = new SysDictTable(_common.TableId);
if (sysDictTable)
{
for(i=1; i<=sysDictTable.fieldCnt(); i++)
{
fieldId = sysDictTable.fieldCnt2Id(i);
sysDictField = sysDictTable.fieldObject(fieldId);
if (sysDictField.isSystem())
continue;
value = '';
if (sysDictField.baseType() == Types::Container)
{
value = enum2str(sysDictField.baseType());
}
else if (sysDictField.arraySize() == 1)
{
value = _common.(fieldId);
}
map.insert(sysDictTable.name()+'.'+sysDictField.name(), value);
}
}
me = map.getEnumerator();
while (me.moveNext())
{
info(strfmt("%1 = %2", me.currentKey(), me.currentValue()));
}
}
You can create an XML and XSLT combo and that would allow you pass simple generated XML files to your template and you would just modify the XSLT and upload it. You can see how to do this from my blog post here:
http://alexondax.blogspot.com/2013/12/how-to-create-xslt-to-transform-ax-xml.html
Upvotes: 3