Showing posts with label Import. Show all posts
Showing posts with label Import. Show all posts

Wednesday, August 31, 2022

Module has invalid reference to module ... Resolving a missing reference during Package deployment


While working on a project and moved to another Development environment , I imported an Model (D365) that caused me to have the following error when I tried to build the models.

The reason is when one model is dependent on a second model and the second model is dependent on the first model.It means one model contains a reference of second model and second model also contains the reference of first model.


Resolution

1. Go to the AOSService folder located on the main drive.
2. In the AOSService folder open the PackagesLocalDirectory folder.
3. Now in this folder, you’ll find all the models. Locate your model and open the folder.
4. In this folder locate to Descriptor Folder.
5. Copy this file to any location of your choice and open it in any text editor.
6. Remove the tag that contains the model which is not present and is the source of the error.
7. Finally copy this file back to the original location and replace the file in the destination folder.
8. Refresh models in Visual Studio and you’re good to go.


 





Sunday, August 7, 2022

D365 FO - Code to Import data from excel file

 D365 FO - Import data from excel file 

Create Table ImportProductTable with 2 Fields 



Create xlsx excel file with 2 fields ItemID , ItemName


using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;
public static class EcoResProductListPage_Extension
{
 [FormControlEventHandler(formControlStr(EcoResProductListPage, UploadProductButtonControl), FormControlEventType::Clicked)]
    public static void UploadProductButtonControl_OnClicked(FormControl sender, FormControlEventArgs e)
    {

        System.IO.Stream                     stream;
        ExcelSpreadsheetName            sheeet;
        FileUploadBuild                       fileUpload;
        DialogGroup                             dlgUploadGroup;
        FileUploadBuild                       fileUploadBuild;
        FormBuildControl                    formBuildControl;
        ImportProductTable _ImportProductTable;

        COMVariantType                     type;
        Dialog                      dialog =    new Dialog('Import Products');
        int rowCount2=10;
  
        dlgUploadGroup          = dialog.addGroup('@SYS54759');
        formBuildControl        = dialog.formBuildDesign().control(dlgUploadGroup.name());
        fileUploadBuild           = formBuildControl.addControlEx(classstr(FileUpload), 'Upload');
        fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
        fileUploadBuild.fileTypesAccepted('.xlsx');
         
        str COMVariant2Str(COMVariant _cv)
        {
            switch (_cv.variantType())

            {
                case COMVariantType::VT_BSTR:
                    return _cv.bStr();
                case COMVariantType::VT_EMPTY:
                    return'';
                default:
                    throw error(strfmt('@SYS26908', _cv.variantType()));
            }

        }

        if (dialog.run() && dialog.closedOk())
        {
        
            FileUpload fileUploadControl     = dialog.formRun().control(dialog.formRun().controlId('Upload'));
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
            if (fileUploadResult != null && fileUploadResult.getUploadStatus())

            {
                stream = fileUploadResult.openResult();
                using (ExcelPackage Package = new ExcelPackage(stream))

                {
          
                    int                         rowCount, i,columncount,j;
                    RecId  _RecId;
                    Package.Load(stream);
                    ExcelWorksheet   worksheet   = package.get_Workbook().get_Worksheets().get_Item(1);
                    OfficeOpenXml.ExcelRange    range       = worksheet.Cells;
                    rowCount           = (worksheet.Dimension.End.Row) - (worksheet.Dimension.Start.Row)  + 1;
                    columncount      = (worksheet.Dimension.End.Column);

                    ttsbegin;
                    delete_from _ImportProductTable;
                    ttscommit;

                    for (i = 2; i<= rowCount; i++)

                    {
                        _ImportProductTable.ItemId  =   range.get_Item(i, 1).value ;
                        _ImportProductTable.ItemName  =   range.get_Item(i, 2).value ;
                        _ImportProductTable.insert();
                    }
                    info(strFmt("%1 rows inserted.",rowCount));
                }
            }

            else
            {
                error('Error here');
            }

        }
        
    }
}