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

Label Extension D365FO

Label Extension  D365FO



As We, All know Label Extension is not available in D365FO in the same way we use to create form, Table, and class Extension...


You can check the below screenshot Label extension option is gray/disable in the menu.



What is the resolution?

There is a way to create an extension of Existing label files.
Add a new label file like the below image... In my demo, I am Creating an Extension of the Sys Label file. 

In Extension use Prefix of Existing Label File name then Add _Extension as Postfix




In my case file name was Sys_Extension. Now click on Add button and complete the wizard.


Select the Language is in use by Parent Label file and click on next ...



You can create a new Label and override the existing one, For Demo purposes, I have created Two Labels @SYS456 which is New Label, and the second I created @SYS12 which is already Exists in SYS Label File... We created this one to override the existing Label.





Now I have created a Menu Item and assign the @SYS456 Label to Menu Items...





To handle the Override case, I have created a class for the verification...

class SLD_DemoClass
{

     
        public static void main(Args _args)
    {
   
        info(SysLabel::labelId2String2(literalstr('@SYS12'), 'en-US'));
        info(SysLabel::labelId2String2(literalstr('@SYS456'), 'en-US'));
    }

}




Support Faryal's Cusine


FormHasMethod extension in D365FO

 FormHasMethod extension in D365FO


Every developer who has started working on D365FO faces this issue that when we create a method in the form of Extension

For verification of method exists or not in the run time, we can use Global::formHasMethod but it does not work with form extensions

So I advise everyone to use the below code is working... 


Source Link


using  System.Object;
using  Microsoft.Dynamics.Ax.Xpp;
using  System.Reflection;
    [ExtensionOf(classStr(Global))]
 final class Global_Extension
{
    static boolean formHasMethod(FormRun _fromRun, IdentifierName _methodName)
    {
        boolean flag= next formHasMethod(_fromRun_methodName);

        if (flag==true)
        {
            flag= Global::VerifyformExtensionHasMethod(_fromRun_methodName);
        }

        return ret;
    }

    private static boolean VerifyformExtensionHasMethod(FormRun _formRun, IdentifierName _methodName)
    {
        

        try
        {
            System.Object[] extensions = ExtensionClassSupport::GetExtensionsOnType(_formRun.GetType(), true);

            if (extensions)
            {
               System.Type    formExtensionType;
               MethodInfo    mInfo;
             
                var  bindingFlags = BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase;

                for (int i = 0; i < extensions.Length; i++)
                {
                    formExtensionType= extensions.GetValue(i);

                    var info = formExtensionType.GetMethods(bindingFlags);

                    for (int J = 0; J < info .get_Length(); J++)
                    {
                        mInfoinfo .getValue(J);
                        if (mInfo.Name == _methodName)
                        {
                            return true;
                        }
                    }
                }
            }
        }
        catch (Exception::CLRError)
        {
            error(CLRInterop::getLastException().ToString());
        }

        return false;
    }

}



Support Faryal's Cusine


Display method for table extension D365FO


A display method for table extension D365FO


As we all know there is no option to create a method in table extension and most of the time we have a requirement to create a display method.

Following are the steps.



Step-1  

Create a class Extension of the table where you can write the display method.

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
}


Step-2  

Create the display methods in the class 

public static class CustTable_Extension
{
[SysClientCacheDataMethodAttribute(true)]  
public static display Name custGroupName(CustTable _this)
{
return  CustGroup::find(_this.CustGroup).Name;
}
}



Support Faryal's Cusine


Avoid Over layering in Development of Workflows on Existing Form


Workflow Extension (alternate way)



As we all know that over-layering is restricted by Microsoft in D365FO and in extension canSubmitToWorkflow not working at all.


Last week, I have received the requirement from my project manager to create a custom workflow on the Transfer order form. as I mentioned that over-layering is not allowed. After few hours of brainstorming within the team, we decided to create a custom workflow with the new table which we will use sort of extension and associate the table with the Transfer order form.

Following are the steps to create a custom workflow and associate it with the existing form.

Prerequisite.
Basic workflow knowledge required. 


Step-1 Create a custom Enum or you can use existing.

Reference screenshot.


Step-2 Create a custom table and add two fields Transfer order Id and Status field extend both fields with appropriate Enum or EDTs. In our case Table name is SLD_TransferOrderWorkflow

Reference screenshot.


Step-3 Create relation on Invent Transfer table and our newly created table on the basis of Transfer Order Number.

Reference screenshot.



Step-4 Create Custom Query and Add the SLD_TransferOrderWorkflow table.
Step-5 Create workflow Type.  

Reference screenshot.



Step-6 Create workflow Approval.

Reference screenshot.



Step-7 Drag the workflow approval in workflow type.

Reference screenshot.


Step-8 Override the canSubmitToWorkflow  on SLD_TransferOrderWorkflow.

Reference screenshot.


Step-9 Create a method in the table to update the status on workflow events/approval.

Reference screenshot.



Step-10 Place proper labels on workflow types, approval, and menu items.

Step-11 Build the model and perform the database sync.

Step-12 Now navigate to the workflow form of your module and click on new to create a new workflow.

You can check in the below screenshot my workflow is appearing.

Reference screenshot.



Step-13 configure workflow as per your requirement and activate.

Step-14 Create an extension of the form on which you want to associate workflow. in my case form was inventTransferTable.

Step-15 Add data source table and join with the parent data source. in my case parent table was inventTransferTable.

Step-16 Only two types of joins are supported. Inner and outer.. in my case, I am using inner because I don't have previous records.  but recommend outer join if you have previous records.

Reference screenshot.



Step-17 Now override the initialized method of the newly added (SLD_TransferOrderWorkflow) data source and enable the workflow.

Reference screenshot.



Step-18 Now override the parent table Methode OnWritten and insert the record on our newly added data source as well. Whenever users create or update the Transfer table.  In my case invent transfer table was a parent.

Reference screenshot.




 Step-19 Now build the model and create the new transfer order and verify. for me its working fine without over-layering.

Reference screenshot.





Please feel free to contact me if you are facing any issues during the implementation of this blog.

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...