Skip to main content

Notifications

D365FO : Import General Journal Using Data entities with restricted access to Data management .

Sukrut Parab Profile Picture Sukrut Parab 71,656 Moderator

As you all already aware of , we can use features like data management , open in excel to import data in dynamics 365 for operations. Open is excel feature is widely used for importing data in general Journals and other areas. However for larger set of data its little bit time consuming. So requirement came to me that we don’t want to provide full access to data management workspace to users but we need ability to import data from general Journal screen itself using data entities, open in excel feature uses data entities as well but importing data directly from data entity its much faster compared to using open in excel feature. You can use standard security architecture to give restrictive access to data management workspace to users but here is another way to execute data entities by directly clicking button from general Journal screen which redirects to data management import screen with just particular entity added.

This is very good option with minimum code as compared to earlier version , in earlier versions sometimes we write custom classes just to import data from excel , CSV etc.

You can create extension to form LedgerJournaltable form and add a button to import data from excel ,csv etc.. In my scenario I took an example of importing from excel .

You can see in below image I added button “Import lines” .

GLBI1.JPG

 

Once you click this Button it takes to import screen in data management as shown below where user can add file using add file button and click on Import to import journal Lines. When this screen is open after clicking on button , system gives message about generating mapping you can click no at this time as when we upload file its going to generate mapping again. As you can see in the image below everything is prepopulated on this screen like definition group name , entity name , file format etc.

GLBI3.JPG

 

Click on add file button and upload file , system will ask you for overwriting existing entity and generation mapping, click yes both the times. To generate excel template you can simply create excel export project and download package, which will give you excel template which we can use in Import process.

GLBi7.JPG

 

Once you upload file and generate mapping successfully click on Import button at the top of screen. As you can see in the screenshot below, once job is finished Journal lines get uploaded in the journal.

GLBI5.JPG

 

GLBI6.JPG

 

Below is the code I used to open import screen from General Journal.

I just copied onclicked eventhandler for that button and implemented it in my extension class as below

[FormControlEventHandler(formControlStr(LedgerJournalTable, caaImportLines), FormControlEventType::Clicked)]
    public static void caaImportLines_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        DMFDefinitionGroup  DMFDefinitinGroup;
        TAParameters        TAParameters = caaTAParameters::find();
        #SysSystemDefinedButtons

        select firstonly DMFDefinitinGroup where DMFDefinitinGroup.DefinitionGroupName == caaTAParameters.GLImportDefinitionGroup;
    
        DMFEntity dmfEntity;
        Args args = new Args();
        FormRun formRun;
    
        args.name(formStr(DMFQuickImportExportEnhanced));
        args.caller(sender.formRun());
        args.record(DMFDefinitinGroup);
    
        args.openMode(OpenMode::Edit);
        args.parmEnumType(enumName2Id(enumStr(DMFOperationType)));
        args.parmEnum(DMFOperationType::Import);
    
        formRun = classfactory.formRunClass(args);
        formRun.init();
        formRun.run();

        select firstonly EntityName from dmfEntity
                    where dmfEntity.TargetEntity == tableId2Name(tableNum(ExpenseJournalLineEntity));
    
            
        FormCheckBoxControl             entityTruncateData = formRun.control(formRun.controlId('DMFDefinitionGroup_TruncateEntityData')) as FormCheckBoxControl;
        FormDropDialogButtonControl     AddEntity = formRun.control(formRun.controlId('AddEntity')) as FormDropDialogButtonControl;
        FormDropDialogButtonControl     AddMultiple = formRun.control(formRun.controlId('AddMultiple')) as FormDropDialogButtonControl;
        FormDropDialogButtonControl     AddTemplate = formRun.control(formRun.controlId('AddTemplate')) as FormDropDialogButtonControl;
        FormCommandButtonControl        RemoveEntity = formRun.control(formRun.controlId('RemoveEntity')) as FormCommandButtonControl;
        FormControl                     standardView = formRun.design().control(formRun.controlId('StandardView')) as FormControl;
        FormControl                     openinExcel = formRun.design().control(formRun.controlId('OpenEntityInExcel')) as FormControl;
        
        FormFunctionButtonControl       DefinitionGroupAccess = formRun.design().control(formRun.controlId('DefinitionGroupAccess')) as FormFunctionButtonControl;
        FormFunctionButtonControl       DefinitionGroupDataArea = formRun.design().control(formRun.controlId('DefinitionGroupDataArea')) as FormFunctionButtonControl;
        FormFunctionButtonControl       DownloadPackage = formRun.design().control(formRun.controlId('DownloadPackage')) as FormFunctionButtonControl;
        FormFunctionButtonControl       RecurringDataJob = formRun.design().control(formRun.controlId('RecurringDataJob')) as FormFunctionButtonControl;

        FormCommandButtonControl        newButton = formRun.design().control(formRun.controlId(#SystemDefinedNewButton)) as FormCommandButtonControl;
        FormCommandButtonControl        deleteButton = formRun.design().control(formRun.controlId(#SystemDefinedDeleteButton)) as FormCommandButtonControl;
        
        

        entityTruncateData.value(0);
        entityTruncateData.allowEdit(false);
        AddEntity.visible(false);
        AddMultiple.visible(false);
        AddTemplate.visible(false);
        RemoveEntity.visible(false);
        standardView.visible(false);
        openinExcel.visible(false);
        DefinitionGroupAccess.visible(false);
        DefinitionGroupDataArea.visible(false);
        DownloadPackage.visible(false);
        RecurringDataJob.visible(false);
        newButton.visible(false);
        deleteButton.visible(false);

        DMFEntityBase::addEntityForProcessing(
                DMFDefinitinGroup.DefinitionGroupName,
                DMFDefinitinGroup.Description,
                dmfEntity.EntityName,
                'EXCEL',
                '',
                'AllFields',
                noyes::No,
                NoYes::yes,
                '',
                DMFDefinitinGroup.TruncateEntityData,
                DMFRefreshType::FullPush,
                false);
            
        formRun.wait(true);

    }


As you can see in the above code I am just calling DMFQuickImportExportEnhanced form through code with operation type as Import . I have hardcoded name of the Definition group here but you can parametrized it. Entity to import data can be selected from DMFEntity table . You can use LedgerJournalEntity or ExpenseJournalLineEntity . In my case I used ExpenseJournalLineEntity.

I am disabling the extra button controls like remove entity , add entity from users as I don’t want to give them ability to do any changes on this screen, you can use Standard security to disable these buttons as well. I felt doing this in a code is also not time consuming.

Not exactly similar but close to this functionality is exist in expense module wherein they create new definition group every time you click on import credit card transaction button, I don’t want user to create new import project every time they click this button so kept that project as a parameter. This helps in avoiding unnecessary data projects and they can see job history from their previous runs in a single project.


 

 

Comments

*This post is locked for comments

  • sang thanh sang Profile Picture sang thanh sang 30
    Posted at
    TAParameters includes what it where?
  • Sukrut Parab Profile Picture Sukrut Parab 71,656 Moderator
    Posted at
    That's a custom table used to parameterized the data project /definition group name.
  • veera seenivasan Profile Picture veera seenivasan 575
    Posted at
    Hi Sukrut, Thanks for the post. I have to implement the same thing for my customer but I don't understand what table I have to specify to import gl lines. caaTAParameters caaTAParameters = caaTAParameters::find();