Showing posts with label Extension Framework. Show all posts
Showing posts with label Extension Framework. Show all posts

August 05, 2022

Create Code extension in D365FO

Hi Folks, 

In case you missed this, Microsoft recently added one more option in Visual Studio to create an extension 'class' of any object (not as an object extension but an extension class to add code/new method).

Navigate to 'Application explorer' (aka AOT) and find your object, right click on this and you will find an option to 'Create code extension', if you select this, it will create a class with all syntax you need to create an extension of that object (i.e. final keyword, add 'ExtensionOf' at the top).


This action will create a class with the name 'ObjectName_Model_Extention' in your project with the below syntax, 









This is super quick to create an extension call for any applicable object. (Yeah you can not create an extension on an EDT using this option ;) )

Cheers!!! Happy Weekend. 

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

April 20, 2022

Table event methods

Hello, 

Here are quick examples of the most important event methods on a table,




I will be posting a video to explain this in Hinglish. Please stay tuned to my YouTube channel 


-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

October 15, 2018

Table Event handler methods in Dynamics 365 FO

Hi Guys,

In my last post Form Event hander methods in Dynamics 365 FO, we discussed different event handlers which available on Form.  Let’s continue this discussion with Table event handler method today.
Let’s see the different type of event handler in today’s post.
You need to add a new class to write the event handler methods. I would recommend adding one class to one table. To make it easy for another developer postfix the name by EH or eventHander or Hander so your teammate can identify if they need to add more business logic than create a new class from scratch.

1. Table onValidateField event handler



2. Table OnValidated event hander (same logic you can try for many other event hander)
[DataEventHandler(tableStr(InventLocation), DataEventType::ValidatedField)]
public static void InventLocation_onValidatedField(Common sender, DataEventArgs e)
{
InventLocation inventLocation = sender as InventLocation;
ValidateFieldEventArgs fieldArgs = e;
boolean ret;
InventLocation inventLocationLoc;
switch(fieldArgs.parmFieldId())
{
case fieldNum(InventLocation, field1):
if(inventLocation.MyWorkerAssociate != '')
{
<Your code/ business ogic/validation>
<ret = true or false>
fieldArgs.parmValidateResult(ret);
}
}
}

Let me know if it helps you or you got some more example.

Cheers,
Harry
Follow us on Facebook to keep in rhythm with us. @Facebook

August 12, 2018

Edit/Display or new methods on standard application objects

Hi Folks,
Let’s see how to write a new method on standard application object using the extension framework. An extension enables you to add functionality to existing model elements and source code.
Before starting adding new method, you need to create a new extension class for your object and this class should be declared as final and post fixed by ‘Extension’ keyword. See below example,

For Table:
[ExtensionOf(tableStr(CustTable))]
final class MyCustTable_Extension
{
<new methods>
}

For Class:
[ExtensionOf(classStr(CustExchAdj))]
final class MyCustExchAdj_Extension
{
<new methods>
}

For Form:
[ExtensionOf(formStr(VendParameters))]
final class MyVendParameters _Extension
{
<new methods>
}

Now lets see how to add different types of methods

1. New edit method
For Extension methods, the first argument in method parameter must be the object you're extending e.g. table buffer. See below code for reference;
public static edit str60 MyFieldEdit(<tableName> _this, boolean _set, name value)
{
MyTable mytable = <tablename>;
if(_set)
{
if(value)
{
ttsbegin;
custTable = CustTable::find(<tablename>.CustAccount,true);
custTable.Name = value;
custTable.update();
ttscommit;
}
}
}

2. New display method
public static display EcoResDescription productName(InventSum _this)
{
Return _this.itemName();
}

3. Normal method
In the same way, you can write a new method, this method also needs to be static so it can be accessed on the form.
Public static updateSearchName(_this, Name _newName)
{
Mytable mytable = _this;
If(_newname)
{
Ttsbegin;
Mytable.searchName = _ newname;
MyTable.update();
Ttscommit;
}
}

Edit method on table extension or new methods on table extension, all method needs to be static. Now to access these methods, go to your form and add new field type of string/real/XYZ. Set below property
clip_image002

Cheers,
Harry