Tag Archives: import
Import, Export and Uninstall the model from Microsoft Dynamics AX 2012
Introduction: In this blog, we will see how we can import, export and uninstall the model from Microsoft Dynamics AX 2012 Details: Prerequisite for import, export and uninstall the model from the environment, run the command prompt as in administrator mode. Form Importing the model script: Install-AXModel -File “Path_Of_the_Model_File” -server ServerName -database DatabaseName_Model –Details Exmaple: Install-AXModel -File “D:\Model\VARModel.axmodel” -server CFSEnvVM -database DAX2012R3CFSEnv_Model –Details Form Exporting the model script: Export-AXModel -Model ‘Model’ -File ‘Path’ -server ‘ServerName\DBName’ -database ‘DatabaseName_Model’ Exmaple: Export-AXModel -Model ‘CUS Model’ -File ‘C:\ModelFile\CUSModel.axmodel’ -server ‘TESTSERVER\CFSDAXSQL2014’ -database ‘DAX2012R3Blank_model’ Form Uninstalling the model script: Uninstall-AXModel -Model ‘Model’ -server ‘ServerName’ -database ‘DatabseName_Model’ Exmaple: Uninstall-AXModel -Model ‘VAR Model’ -server ‘CFSEnvVM’ -database ‘DAX2012R3Test_model’ Thanks for reading !!!
x++ code to import data from excel to D365 FnO
We can also import data through code in D365 FO. Data import through code in D365 works differently than Ax2012 since cloud services. Import Class we are trying to import data from Excel to D365FO through the following code. using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; using OfficeOpenXml.ExcelRange; class EmplAttendance { public void run() { this.updateDailyAttendance(); } void updateDailyAttendance() { System.IO.Stream stream; ExcelSpreadsheetName sheeet; FileUploadBuild fileUpload; DialogGroup dlgUploadGroup; FileUploadBuild fileUploadBuild; FormBuildControl formBuildControl; EmplAttendance_CFS emplTimeAttendance, insertTimeAttendance, updateTimeAttendance; COMVariantType type; Dialog dialog = new Dialog(“Daily Attendance Imported”); 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; 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); for (i = 2; i<= rowCount; i++) { str Emplid; TransDate WorkingDate; emplid = (range.get_Item(i, 1).value); WorkingDate = str2Date((range.get_Item(i, 2).value),123); select * from emplTimeAttendance where emplTimeAttendance.EmplId = = Emplid && emplTimeAttendance.WorkingDate = = WorkingDate; if(emplTimeAttendance) //if record already exists update it { emplTimeAttendance.selectForUpdate(true); emplTimeAttendance.Timein = any2Str(range.get_Item(i, 3).value); emplTimeAttendance.Timeout = any2Str(range.get_Item(i, 4).value); emplTimeAttendance.OT = any2Real(range.get_Item(i, 5).value); ttsbegin; emplTimeAttendance.update(); ttscommit; } Else //insert the new record { insertTimeAttendance.EmplId = (range.get_Item(i, 1).value); insertTimeAttendance.WorkingDate = str2Date((range.get_Item(i, 2).value),123); insertTimeAttendance.Timein = any2Str(range.get_Item(i, 3).value); insertTimeAttendance.Timeout = any2Str(range.get_Item(i, 4).value); insertTimeAttendance.OT = any2Real(range.get_Item(i, 5).value); insertTimeAttendance.insert(); } } } } else { error(“Error here”); } } } public static void main (Args args) { EmplAttendance emplDailyAttendanceImport; emplDailyAttendanceImport = new EmplAttendance (); emplDailyAttendanceImport.run(); } }
Model import and export in D365 Finance and Operations using Powershell
When we want to move customization done on specific model from one environment to other development environment we need to export and import the model file. Steps for model import and export using PowerShell :- Open PowerShell in administrator mode. Change directory to the path of package bin folder. Export command:-.\ModelUtil.exe -export -metadatastorepath=C:\AOSService\PackagesLocalDirectory -modelname=”name of model” -outputpath=path to store model after exportFor example: If model name is TOUpgradeModel and I want to store the model file to path is C:\Temp\ModelFile The command will be as follows: .\ModelUtil.exe -export -metadatastorepath=K:\AosService\PackagesLocalDirectory -modelname=”TOUpgradeModel” -outputpath=C:\Temp\ModelFile Output file you can see on the specified path as Import Command :-.\ModelUtil.exe -import -metadatastorepath=C:\AOSService\PackagesLocalDirectory -file=the path from. axmodel to importFor example: .\ModelUtil.exe -import -metadatastorepath=C:\AOSService\PackagesLocalDirectory -file=C:\Temp\ModelFile\TOUpgradeModel-Cloudfront.axmodel ( Note : If model already exist in your environment, trying to import the same model you will receive the error message of “Model already exist”. So, delete the existing model by command .\ModelUtil.exe -delete -metadatastorepath=C:\AOSService\PackagesLocalDirectory -modelname=” TOUpgradeModel ” try to import the model)