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);
	}
	
}

1 thought on “Extensions examples”

  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 Reply

Discover more from D365 for Finance and Operations

Subscribe now to keep reading and get access to the full archive.

Continue reading