Friday, July 27, 2018

Metadata Lookup - list of forms in D365

Here I am explaining how to write a lookup to get a list of forms and same way we can write a lookup of any metadata lookups.

In AX 2012 we have a table called 'UtilElements' to get the list of objects and then you can filter with 'UtilElementType' in your query.

In 365, they have introduced an API instead to get the list of metaData based on your requirements.

var    forms = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::FormNames();

So for lookup, I have developed a tmp table and that has two columns
1. FormName
2. FormLabel

And that table will get inserted when you open the form where we have a requirement to put the lookup. 
*******************************************************
   SysFormsListTmp    formsList;
    
    public void populateFormsListTmp() // custom method to populate the tmp table
    {
       
        var                     forms = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::FormNames();

        ttsbegin;
        while (forms.MoveNext())
        {
            formsList.clear();
            formsList.FormName = forms.Current;
            formsList.FormLabel = formName2Pname(formsList.FormName);
            formsList.insert();
        }
        ttscommit;

    }

    
    public void init()  //init() method of the form.
    {
        super();
        element.populateFormsListTmp();
    }
******************************************************
And then you can write a lookup() method on your control.

******************************************************
public void lookup(FormControl _formControl, str _filterStr)
{
                
                SysTableLookup sysTableLookup = SysTableLookup::newParameters(Tablenum(SysListOfFormsTmp),_formControl);
                Query query = new Query();
                QueryBuildDataSource queryBuildDataSource;
                
                
                sysTableLookup.addLookupField(fieldNum(SysFormsListTmp, FormName));
                sysTableLookup.addLookupfield(fieldNum(SysFormsListTmp, FormLabel));

                queryBuildDataSource = query.addDataSource(tableNum(SysFormsListTmp));
                queryBuildDataSource.addSortField(fieldNum(SysFormsListTmp, FormName), SortOrder::Ascending);

                sysTableLookup.parmQuery(query);
                sysTableLookup.parmTmpBuffer(formsList);

                sysTableLookup.performFormLookup();

                super(_formControl, _filterStr);
                
    }

Tags: #FormLookup #MetaData #D365FO 

Saturday, July 21, 2018

Power BI - How to embed a PBIX in D365FO and add in a workspace.

We have an option in D365 to embed PowerBI visuals and run through workspaces. Here I am providing steps to do the same.

1. Create a PowerBI report using power BI desktop and save the file, .pbix file will be saved.  You can refer below youTube tutorial

2. Open Visual Studio in your dev box and Right click on your project - Add - New Item 



3. Create a new 'Resource' and give the name of that resource.


4. As soon as you hit the ok, VS will popup the file explorer to select the 'PBIX' file, select the pbix you have developed\created.


5. Hit 'ok', resource will get created in your project.




6. Create a Display Menu Item 'demoAddPowerBiDisplay' and also create a controller class 'demoAddPowerBIWorkSpaceController' and extends with 'PBIReportControllerBase'

Note - You can copy the standard controller class like - 'FinancialInsightsWorkspaceEmbeddedController' 

7. Now add or modify the 'Main' method of the class and call your pbix resource -


8. Add this controller class in your menu item as an object.

9. Now create a new 'Tile' Right click on your project -> Add -> new Items -> User Interface - Tile.

10 . Once created, select your display menu item in tile properties. And give the label.



11. Add this tile to your menu.


12 - Once you click on this workspace, your pbix will get called. 

Tags: #PowerBI #D365FO #Pbix #Dynamics