Tuesday, January 14, 2020

Power BI - How to embed a PBIX using Form 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 'GLInsightsPBIXDisplay' and and create a form with tab and tab pages (can be per report) and  a group  control and then add below code.. Update the tab, tabpage , menu item and pbix names. 

[Form]
public class GLInsightsWorkspace extends FormRun
{
    PowerBIReportSetupHelper helperGL;
    boolean isPowerBIReportGL;
   


    /// <summary>
    ///
    /// </summary>
    private void initPowerBI()
    {
        if (isConfigurationkeyEnabled(configurationKeyNum(PowerBIEmbedded_App)))
        {
            helperGL         = PowerBIReportSetupHelper::construct();
           
            helperGL.parmGroupControl(GLInsightsPBIX);
          
            if (hasMenuItemAccess(menuItemDisplayStr(GLInsightsPBIXDisplay), MenuItemType::Display))
            {
                helperGL.parmIsCrossCompany(true);
                GLInsightsPBIX.caption("GL Insights");
                helperGL.parmResourceName(resourceStr(demoAddPowerBIResource));

            }
          
        }
    }

    /// <summary>
    ///
    /// </summary>
    public void init()
    {
        super();
        this.initPowerBI();
        GLInsights.pageActivated();
    }

    [Control("TabPage")]
    class GLInsights
    {
        /// <summary>
        ///
        /// </summary>
        public void pageActivated()
        {
            super();
            if (!isPowerBIReportGL)
            {
                isPowerBIReportGL = true;
                helperGL.run();
            }
        }

    }

}

8. Add this form 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 

Tuesday, August 13, 2019

How to add an Entity in Data Project through code (X++)

         DMFDefinitionGroupEntity   addEntity;

        if (DMFQuickImportExportFormHelper::validateEntity(_entityName, _sourceName, DMFOperationType::Export))
        {
            ttsbegin;
            addEntity.clear();
            addEntity.initValue();
            addEntity.DefaultRefreshType = DMFRefreshType::IncrementalPush;
            addEntity.DefinitionGroup = _definitionGroup;
            addEntity.Entity = _entityName;
            addEntity.EntityXMLName = _targetEntity;
            addEntity.SkipStaging = NoYes::Yes;
            addEntity.source = _sourceName;
            addEntity.validationStatus = NoYesError::Yes;
            addEntity.ExecutionUnit = NoYes::Yes;
            addEntity.LevelInExecutionUnit = NoYes::Yes;
            addEntity.insert();

            //Generate mapping
            DMFXmlGeneration::generateMappingV2(addEntity);
            ttscommit;
                       
           
        }

Variables -

  1. _entityName - Name of the Entity
  2. _SourceName - Source Data Format (like BYOD, Excel)
  3. _definitionGroup - Definition Group Name (or Data Project Name)

#DataEntities #X++ #D365F&O #DMF

Thursday, June 27, 2019

How to get Azure Blob URL in D365FO


When we are exporting data in Excel or any other format using DIXF, file gets uploaded in Azure Blob and if you need that azure blob URL you can get using below code -

DMFEntityExportDetails      exportDetails;

you can find exportDetails table buffer by passing DMF definition group and entity name. 

str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(exportDetails.SampleFilePath));











#D365F&O #DIXF #DMF 

Thursday, April 4, 2019

How to get the primary table from Data Entity in D365F&O

Overview - How to get the primary table from an entity in D365F&O

 public static TableName getPrimaryTable(TableName _tableName)
    {
        TableName                       tableName;
        Query                               q;
        QueryBuildDataSource   dataSource;

        DictDataEntity dictEntity = new  DictDataEntity(tableName2Id(_tableName));
        if (dictEntity)
        {
            q = dictEntity.query();
            if (q.dataSourceCount() >= 1)
            {
                dataSource = q.dataSourceNo(1);
                if (dataSource)
                {
                    tableName = tableId2Name(dataSource.table());
                }
            }
        }
         
        return tableName;
    }

And if we need all tables from the data entity, we can loop the data source count.

#D365F&O #AX #Entities

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 

Monday, June 11, 2018

Data Entities - Custom Query Change Tracking in D365FO

Requirement is to enable the change tracking on table which is not part of the entity at all. But that table is being used in postLoad() to populate the values in an entity.

Let’s take an example of WMSLocation entity, we have added a custom column in that table and poplulating that column in postLoad method of the entity from some other table (demoLocationType). Now the scenario is when we are updating or adding data in this custom table then system should push or update data in wmsLocation entity.

If we are enabling primary or All table change tracking on entity, system won't update the WMSLocation when we are updating or adding column in table 'demoLocationType'.

Solution - We should write a custom method and name that 'defaultCTQuery' and in that method we would have create a query based on the relation between above two tables WMSLocation and demoLocationType and return the query object.

public static Query defaultCTQuery()
   {
        Query q;

        q = new Query();
        QueryBuildDataSource qbd = q.addDataSource(tablename2id('WMSLocation'));
        qbd = qbd.addDataSource(tablename2id('demoLocationType'));
        qbd.relations(false);
                               qbd.addLink(fieldName2Id(tableName2Id('WMSLocation'),'wMSLocationId'),fieldName2Id(tableName2Id('demoLocationType'),'wMSLocationId'));

        return q;
    }




And then go to Data Entities -> Filter the entity (WMSLocation) ->  Change Tracking -> Enable Custom query.




Tags-  #DataEntities, #ChangeTracking, #MSDYN365FO