Thursday, February 22, 2024

How to get a user group from a workflow work item

 Below code snippet to get the user group for a workflow work item (if user group used for work item assignment)

 WorkflowStepTable stepTable;

str userGroup;

 select stepTable where stepTable.ElementId == WorkflowworkItemTable(buffer).ElementId;

userGroup = WorkflowConfigPersonPicker::newAssignmentTable(stepTable.workflowAssignmentTable()).parmParticipantTokenValue();


Wednesday, October 13, 2021

How To Get Dynamics 365 F&O URL through code - X++

 var app = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();

Str envURL= app.Infrastructure.HostUrl;


#D365F&O #Dynamics #Finance #URL


How to cancel form control super method call

 FormControlCancelableSuperEventArgs cancelSuperEventArgs = e as FormControlCancelableSuperEventArgs;

cancelSuperEventArgs.CancelSuperCall();




















#D365FO #Dynamics #X++ #UI 

Tuesday, February 23, 2021

How to get a list of tables (data sources) in an Entity through code - X++

 public void tableList(TableName _tableName)

    {

        DictDataEntity dictEntity       =     new  DictDataEntity(tableName2Id(_tableName));

        int                                                    dataSourceCount;

        Query                                                query;

        QueryBuildDataSource                    dataSourceName;

        str                                                      entityTableName;

        if (dictEntity)

        {

            query       = dictEntity.query();

            if (query.dataSourceCount() >= 1)

            {

                dataSourceCount = query.dataSourceCount();

            }


            for(int datasource=1;datasource<=dataSourceCount;datasource++)

            {

                dataSourceName    = query.dataSourceNo(datasource);

                entityTableName    = tableId2Name(dataSourceName.table());  

                info(entityTableName );              

            }

        }

    }


#D365F&O #DataEntities #X++ 

Wednesday, June 3, 2020

How to List Down Data Entities with Data Management Enabled- D365F&O

class demoGetListofDataEntityObjects
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        demoGetListofDataEntityObjects entityObj =new demoGetListofDataEntityObjects();
        entityObj.run();
    }

    public void run()
    {
        #define.EnLanguageId('en-us')
        str                     tableName;
        TableName               tn;
        demoDataEntityLabels  elabels; - //Table Variable
        delete_from elabels;

        List                        entityList;
        ListEnumerator              enumerator;
        
        DictDataEntity              dataEntity;
        DMFEntity                   dmfEntity;
        DMFEntityName               entityName;
        entityList = DictDataEntity::listOfDataEntities();
        enumerator = entityList.getEnumerator();

        while(enumerator.moveNext())
        {
            
            dataEntity = new DictDataEntity(tablename2id(enumerator.current()));
            entityName = SysLabel::labelId2String2(dataEntity.labelDefined(), #EnLanguageId);
            if (dataEntity.dataManagementEnabled())
            {
                elabels.clear();
                elabels.TableName = enumerator.current();
                elabels.EntityName = entityName;
                elabels.insert();
            }

        }
        
    }

}

#D365F&O #DataEntities #MSDyn365F&O

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