Extensions examples

Purpose:

The purpose of this post is to share examples of extensions.

Product:

Dynamics 365 for Finance and Operations

Code:

Form data source event handler. Event type: ValidatedWrite

/// <summary>
/// OnValidatedWrite handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataSourceEventHandler(formDataSourceStr(DirPartyQuickCreateForm, DirPartyTable), FormDataSourceEventType::ValidatedWrite)]
public static void DirPartyTable_OnValidatedWrite(FormDataSource sender, FormDataSourceEventArgs e)
{
	#define.CallerFormName("CustTable")

	FormRun formRun = sender.formRun();
	FormDataSource dirPartyTable_DirOrganization_ds = formRun.dataSource(formDataSourceStr(DirPartyQuickCreateForm, DirPartyTable_DirOrganization));
	DirOrganization dirOrganization = dirPartyTable_DirOrganization_ds.cursor();
	FormDataSourceCancelEventArgs args = e as FormDataSourceCancelEventArgs;
	boolean doCancel;

	if (formRun.args().callerName() == #CallerFormName)
	{
		if (!dirOrganization.OrgNumber)
		{
			checkFailed(strFmt("Organization number is required."));
			doCancel = true;
		}
	}

	args.cancel(doCancel);
}

Form event handler. Event type: Initialized

/// <summary>
/// OnInitialized handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormEventHandler(formStr(DirPartyQuickCreateForm), FormEventType::Initialized)]
public static void DirPartyQuickCreateForm_OnInitialized(xFormRun sender, FormEventArgs e)
{
	#define.CallerFormName("CustTable")

	if (sender.args().callerName() == #CallerFormName)
	{
		DimensionEntryControl dimensionEntryControl = sender.control(sender.controlId("DimensionEntryControl"));
		dimensionEntryControl.parmDisplayValues(true);
	}
	
}

One thought on “Extensions examples

Add yours

  1. It was good to watch your post on event handler customization, but sir add some comments with your customizations for readers understanding.

    Thanks and Regards,
    Shabir

Leave a comment

Blog at WordPress.com.

Up ↑