Friday, February 10, 2017
Dynamics 365 - Table Extension Predefined Method() and Userdefined Method():
public static class SalesLine_Extension
{
[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, insert))]
public static void SalesLine_Post_insert(XppPrePostArgs args)
{
SalesLine saleslineLoc;
FormDataSource salesFormDataSource;
saleslineLoc = args.getthis();
if(saleslineLoc.SalesId)
{
Info("SalesID existed");
}
salesFormDataSource = FormDataUtil::getFormDataSource(saleslineLoc);
if(salesFormDataSource)
{
salesFormDataSource.research(true);
}
}
public static void updateDefaultWarehouse(SalesLine _salesLine)
{
InventTable inventTable;
;
inventTable = InventTable::find(_salesLine.ItemId);
}
[DataEventHandler(tableStr(SalesLine), DataEventType::ModifiedFieldValue)]
public static void SalesLine_onModifiedFieldValue(Common sender, DataEventArgs e)
{
SalesLine salesLineLocal = sender;
Table table1;
if(salesLineLocal.SalesId)
{
ttsbegin;
table1.OrderNumber = salesLineLocal.SalesId;
table1.SalesType = salesLineLocal.SalesType;
table1.ItemId = salesLineLocal.ItemId;
table1.insert();
ttscommit;
}
}
[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, update))]
public static void SalesLine_Post_update(XppPrePostArgs args)
{
SalesLine salesLineLocal;
SalesTable salesTable;
salesLineLocal = args.getthis();
ttsbegin;
salesTable = salesTable::find(salesLineLocal.SalesId, true);
if (salesTable)
{
salesTable.FieldId= SalesTable_Extension::MethodName(salesTable);
salesTable.update();
}
ttscommit;
}
[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, modifiedField))]
public static void SalesLine_Post_modifiedField(XppPrePostArgs args)
{
FieldId fieldId = args.getArg('_fieldId');
SalesLine salesLine = args.getThis();
switch (fieldId)
{
case fieldNum(SalesLine, NewItemNumber):
if (salesLine.NewItemNumber)
{
ItemId itemId = salesLine.ItemId;
Info(strfmt("%1, " ItemId"));
}
break;
}
}
[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, delete))]
public static void SalesLine_Post_delete(XppPrePostArgs args)
{
SalesLine salesLine;
TableName tableName;
Args _args = new Args();
salesLine= args.getthis();
if(salesLine.RecId)
{
ttsbegin;
delete_from tableName
where tableName.OrderNumber == salesLine.SalesId
&& tableName.ItemId == salesLine.ItemId
&& tableName.LineNum == salesLine.LineNum;
ttscommit;
}
}
Dynamics 365 - DataSource Method:
public class InventLocation_Extension
{
///
/// Post event handler forInventLocation SalesLine Initialized event.
///
///
///
[FormDataSourceEventHandler(formDataSourceStr(InventLocation, InventLocation), FormDataSourceEventType::Initialized)]
public static void InventLocation_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
InventLocation inventLocation = sender.cursor();
if (inventLocation.InventLocationId)
{
info("There is inventLocation Id existed");
}
else
{
info("There is NO inventLocation Id");
}
}
}
{
///
/// Post event handler for
///
///
///
[FormDataSourceEventHandler(formDataSourceStr(InventLocation, InventLocation), FormDataSourceEventType::Initialized)]
public static void InventLocation_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
InventLocation inventLocation = sender.cursor();
if (inventLocation.InventLocationId)
{
info("There is inventLocation Id existed");
}
else
{
info("There is NO inventLocation Id");
}
}
}
Subscribe to:
Posts (Atom)