Dynamics 365 FO extension
1. 窗体控件不再支持Active X 控件和ManagedHost控件,取而代之的是一种可扩展的控件架构。
2. 获得窗体的DataSource
[FormEventHandler(formStr(HcmPosition), FormEventType::Initialized)]
public static void HcmPosition_OnInitialized(xFormRun sender, FormEventArgs e)
{
FormDataSource hcmosition_ds = sender.dataSource(formDataSourceStr(HcmPosition, HcmPosition));
Or
FormDataSource hcmosition_ds = sender.dataSource('HcmPosition');
}
3. FormDataSource的EventHandler获得FormRun
[FormDataSourceEventHandler(formDataSourceStr(HcmPosition, HcmPosition), FormDataSourceEventType::Created)]
public static void HcmPosition_OnCreated(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun() as FormRun;
}
4. 通过FormControl的EventHandler获得FormRun
[FormControlEventHandler(formControlStr(HcmPosition, HcmPosition_PositionId1), FormControlEventType::Modified)]
public static void HcmPosition_PositionId1_OnModified(FormControl sender, FormControlEventArgs e)
{
FormRun formRun = sender.formRun() as FormRun;
}
5. 获得窗体上的FormControl
[FormEventHandler(formStr(HcmPosition), FormEventType::Initialized)]
public static void HcmPosition_OnInitialized(xFormRun sender, FormEventArgs e)
{
sender.design().controlName(formControlStr(HcmPosition, HcmPositionNewPosition)).AllowEdit(false);
// to get form open Mode
OpenMode openMode = sender.args().openMode();
}
6. 获得Current Record
[FormControlEventHandler(formControlStr(HcmPosition, HcmPositionNewPosition), FormControlEventType::Clicked)] public static void HcmPositionNewPosition_OnClicked(FormControl sender, FormControlEventArgs e) { HcmPosition hcmposition = sender.formRun().dataSource(1).cursor();
HcmPosition hcmposition = sender.args().record(); }
7. 使用DataEventArgs发送验证结果
[DataEventHandler(tableStr(CategoryTable), DataEventType::ValidatingDelete)]
public static void CategoryTable_onValidatingDelete(Common _sender, DataEventArgs _e)
{
CategoryTable categoryTable = _sender as CategoryTable;
ValidateEventArgs validateEventArgs = _e as ValidateEventArgs;
boolean ret = true;
if (categoryTable.UseInProject)
{
ProjCategory projCategory = ProjCategory::find(categoryTable.CategoryId);
ret = projCategory.validateDelete();
}
if (ret && categoryTable.UseInExpense)
{
TrvCostType trvCostType = TrvCostType::find(categoryTable.CategoryId);
ret = trvCostType.validateDelete();
}
if (!ret)
{
validateEventArgs.parmValidateResult(false);
}
}
8. 用 ValidateFieldValueEventArgs 发送验证结果给Validate Field method
[DataEventHandler(tableStr(LedgerParameters), DataEventType::ValidatingFieldValue)]
public static void LedgerParameters_onValidatingFieldValue(Common sender, DataEventArgs e)
{
ValidateFieldValueEventArgs ve = e;
boolean isValid = true;
LedgerParameters ledgerParameters = sender as LedgerParameters;
#isoCountryRegionCodes
if (ve.parmFieldName() == fieldStr(LedgerParameters, ChineseVoucher_CN)
&& SysCountryRegionCode::isLegalEntityInCountryRegion([#isoCN]))
{
if ((select firstonly RecId from LedgerJournalTrans
where LedgerJournalTrans.LedgerVoucherType_CN != 0
|| LedgerJournalTrans.Voucher_CN != '').RecId != 0)
{
// The general journal needs to be empty in order to modify the setup for the Chinese voucher system.
isValid = checkFailed("@GLS54497");
}
ve.parmValidateResult(isValid);
}
}
Form data source event handler
[FormDataSourceEventHandler(formDataSourceStr(EcoResProductDetailsExtended, InventTable), FormDataSourceEventType::Written)]
public static void InventTable_OnWritten(FormDataSource sender, FormDataSourceEventArgs e){
FormRun form = sender.formRun();
FormDataSource InventTable_ds = form.dataSource(formDataSourceStr(EcoResProductDetailsExtended,InventTable)) as FormDataSource;
InventTable inventTable = InventTable_ds.cursor();
}
Form event handler
Table Buffer on form closing event
[FormEventHandler(formStr(EcoResAttributeValue), FormEventType::Closing)]
public static void EcoResAttributeValue_OnClosing(xFormRun sender, FormEventArgs e)
{
FormDataSource ecoResProduct_ds = sender.dataSource(formDataSourceStr(EcoResAttributeValue, EcoResProductAttributeValue));
EcoResProductAttributeValue ecoResAttributeValue = ecoResProduct_ds.cursor();
}
Control value and form event level for which auto declaration must be set true
[FormControlEventHandler(formControlStr(EcoResProductCreate, OKButton), FormControlEventType::Clicked)]
public static void OKButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormRun element = sender.formRun();
//form control
FormControl modelGroupRef = element.design(0).controlName("ModelGroupId");
Info(strfmt(“Model Group %1”, modelGroupRef.valueStr()));
//form parameter
ItemId itemId = element.parmItemId();
}
Post handler for class method
[PostHandlerFor(classStr(EcoResProductReleaseManager), methodStr(EcoResProductReleaseManager, release))]
public static void EcoResProductReleaseManager_Post_release(XppPrePostArgs args){
EcoResProductReleaseManager releaseMgr;
//Getting the class object
releaseMgr = args.getThis();
//Getting the class parameter
ItemId itemId = releaseMgr.parmItemId();
//Getting the method argument
boolean itemCreation = args.getArg("_isCreation");
}
Post handler for overriding table methods modified field and validate Write
[PostHandlerFor(tableStr(InventTable), tableMethodStr(InventTable, validateWrite))]
public static void InventTable_Post_validateWrite(XppPrePostArgs args)
{
InventTable inventTable = args.getThis() as InventTable
boolean ret = true;
// Override the validations here and set the return value accordingly.
Args.setReturnValue(ret);
}
[PostHandlerFor(tableStr(InventTable), tableMethodStr(InventTable, modifiedField))]
public static void InventTable_Post_modifiedField(XppPrePostArgs args)
{
//Getting the table buffer
InventTable inventTable = args.getThis() as InventTable
//Getting the field id method argument.
FieldId fieldModified = args.getArg("_fieldId");
switch (fieldModified)
{
//Here you can write your logic on modified field method
break;
}
}
窗体内的方法
[ExtensionOf(formStr(PurchTable))]
final class RIC_PurchTable_Extension
{
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[PostHandlerFor(formStr(PurchTable), formMethodStr(PurchTable, updateControlsForFrenchConfirmedPO))]
public static void PurchTable_Post_updateControlsForFrenchConfirmedPO(XppPrePostArgs args)
{
FormRun sender = args.getThis();
FormDataSource purchTable_DS;
PurchTable purchTable;
boolean canEnable;
if (PublicSectorUtils::isFrenchRegulatoryEnabled())
{
purchTable_DS = sender.dataSource(formDataSourceStr(PurchTable, PurchTable));
purchTable = purchTable_DS.cursor();
canEnable = purchTable.canModifyPurchaseOrder();
purchLine_PurchPriceGrid.allowEdit(canEnable);
}
}
}
Override Form DataSource method using Extensions in D3fO
[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)] public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e) { FormDataSource fds = sender.formRun().dataSource("SalesLine"); SalesLine salesline = fds.cursor(); FormRun fr = sender.formRun(); FormControl fc = fr.design(0).controlName("CreateServiceOrder"); if(salesLine.ProjID) { fc.enabled(true); } else { fc.enabled(false); } }
————————————————
版权声明:本文为CSDN博主「mahailiang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mahailiang/article/details/80080209
posted on 2021-11-12 19:12 lingdanglfw 阅读(338) 评论(0) 编辑 收藏 举报