Sunday, September 17, 2017

Microsoft Dynamics Ax 2012: Difference between modifiedField and modifiedFieldValue methods

Problem description
In a project for a customer I had an issue that some business logic didn’t work. During an import of related data we found out that everything in test and debugger worked fine, but it didn’t work in batch.
Solution
To solve this we moved the code from the modifiedFieldValue method to the modifiedField method and this solved the issue.
So this means that the code in the modifiedFieldValue isn’t executed in batch (CIL) which is different from the modifiedField method. This method is executed on the client, server and the batch.
I couldn’t find documentation on the internet about this. So be aware that the client execution of code can differ from the batch.

Reference : http://www.van-veldhuizen.eu/blog/2012/06/08/microsoft-dynamics-ax-2012-difference-between-modifiedfield-and-modifiedfieldvalue-methods/

Thanks

Thursday, September 14, 2017

Custom workflow in ax 2012

Dear Friends,

I have come to know a very good blog for a custom workflow in ax 2012, you can go to the blog reference and check

http://www.axpulse.com/dynamics-ax-2012-custom-workflow/

Thanks
B K Sharma

Monday, September 11, 2017

Upload excel data to Ax Table

Hi,

To upload excel data to ax table we use following x++ code

static void UploadExceldatatoTable(Args _args)
{
   SysExcelRange                       sysExcelRange;
   #AviFiles
   #define.Star('*')
   #define.ExcelDataRange("A1:IV65536")
   SysOperationProgress                _progressBar = new SysOperationProgress();
   int                                 record;
   DialogField                         dialogPath;
   Dialog                              dialog;
   Filename                            filename;
   CommaIO                             inFile;
   SysExcelApplication                 xlsApplication;
   SysExcelWorkBooks                   xlsWorkBookCollection;
   SysExcelWorksheets                  xlsWorkSheetCollection;
   SysExcelWorksheet                   xlsWorkSheet;
   SysExcelCells                       Cells;
   SysExcelCell                        RCell;
   int                                 nRow; //,i;
   NoYes                               _NoYes;
   TimeOfDay                           time;
   S3_FrequencyIdentifier                      _frequency;
   S3_EquipmentTypes                           eqptTypeMaster;
   WCL_bk_EqptTaskLastInspectionDate           _eqptTaskLastInspDate;
   WCL_SS_RouteEquipment                       _RouteEquipment;
   S3_EquipmentTable                           _eqptTable;
   WCL_InspectionCheckListHeader               _inspChkLstHeader;
   WCL_InspectionCheckListLines                _inspChkLstLine;
   #Excel
   // convert into str from excel cell value
   str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
   {
       switch (_cv.variantType())
       {
           case (COMVariantType::VT_BSTR) :
           return _cv.bStr();
           case (COMVariantType::VT_R4):
           return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
           case (COMVariantType::VT_R8):
           return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
           case (COMVariantType::VT_DECIMAL):
           return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
           case (COMVariantType::VT_DATE):
           return date2str(_cv.date(),123,2,1,2,1,4);
           case (COMVariantType::VT_EMPTY):
           return "";
           default:
           throw error(strfmt("@SYS26908", _cv.variantType()));
       }
   return "";
   }
   ;
   dialog = new Dialog('Equipment task Last inspection date import');
   dialogPath = dialog.addField(extendedTypeStr(Filenameopen), 'File Name');
   dialog.run();
   if (dialog.run())
   {
       filename = (dialogPath.value());
   }
   inFile = new CommaIO (filename, 'R');
   if (!inFile || infile.status() != IO_Status::Ok )
   {
       throw error (strfmt("@SYS19312",filename));
   }
   try
   {
       xlsApplication          = SysExcelApplication::construct();
       xlsWorkBookCollection   = xlsApplication.workbooks();
       xlsWorkBookCollection.open(filename);
       xlsWorkSheetCollection  = xlsApplication.worksheets();
       xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
       Cells                   = xlsWorkSheet.Cells();
       nRow = 2;
       RCell = Cells.Item(nRow, 1);
       sysExcelRange           = xlsWorkSheet.cells().range("A1:IV65536");
       sysExcelRange           = sysExcelRange.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
       if (sysExcelRange)
       {
           record = sysExcelRange.row();
       }
       _progressBar.setCaption("Last inspection date uploading. . .");
       _progressBar.setAnimation(#AviUpdate);
       _progressBar.setTotal(record);
       ttsBegin;
       while (COMVariant2Str(RCell.value()) != "")
       {
           _progressBar.setText(strfmt("Step %1", nRow));
           _progressBar.setCount(nRow, 1);
           if(WCL_SS_RouteMaster::find(strLTrim(strRTrim(COMVariant2Str(Cells.item(nRow,1).value())))))
           {
               while select _RouteEquipment join _eqptTable join _inspChkLstHeader join _inspChkLstLine
                 where _RouteEquipment.EquipmentId           == _eqptTable.S3_EquipmentId &&
                       _eqptTable.EquipmentType              == _inspChkLstHeader.EquipmentType &&
                       _eqptTable.EquipmentSubType           == _inspChkLstHeader.EquipmentSubType &&
                       _inspChkLstHeader.CheckListHeaderID   == _inspChkLstLine.CheckListHeaderID &&
                       _RouteEquipment.RouteID               == strLTrim(strRTrim(COMVariant2Str(Cells.item(nRow,1).value()))) &&
                       _inspChkLstLine.Frequency             == _frequency
               {
                   if(!WCL_bk_EqptTaskLastInspectionDate::find(_RouteEquipment.EquipmentId, _inspChkLstLine.TaskCode))
                   {
                       _eqptTaskLastInspDate.EquipmentId           = _RouteEquipment.EquipmentId;
                       _eqptTaskLastInspDate.TaskCode              = _inspChkLstLine.TaskCode;
                       _eqptTaskLastInspDate.LastInspectionDate    = str2Date(strLTrim(strRTrim(COMVariant2Str(Cells.item(nRow,3).value()))),123);
                       _eqptTaskLastInspDate.insert();
                   }
               }
           }
           else
           {
               error(strFmt("%1 - Route not found in the master",strLTrim(strRTrim(COMVariant2Str(Cells.item(nRow,1).value())))));
           }
           nRow++;
           RCell = Cells.Item(nRow, 1);
       }
       ttsCommit;
       info("Equipment Task last inspection date uploaded successfully");
   }
   catch
   {
       error('Error!');
       xlsApplication.quit ();
       xlsApplication.finalize ();
       return;
   }
}

Thanks
B K Sharma

Print/Insert Image (.jpeg) object in SSRS Report (AX 2012 R3) attach via Document handling

Hi Friends,
I am presenting a process to print/Insert the Ax document handling attached image/file in a SSRS report in ax 2012 r3. Below example taken from purchase order attached file in document handling.

1. When we open purchase order list page than we can open document handling form from attachment menu item where we can add any type of file to this form, here we are attaching a image file.
2. After attachment of file now we want to print this image to our SSRS report, so basic method we are using to complete this task is to use image URL as image source in ssrs report. To get the image url we will use this query from DocuRef table and join it to the PurchTable
- This query is used in ProcessReport method of RDP class of SSRS report.

select docuRef where docuRef.RefCompanyId == PurchTable::find(vendInvoiceJour.PurchId).dataAreaId &&
docuRef.RefRecId == PurchTable::find("TestPO0001").RecId && 
docuRef.RefTableId == PurchTable::find("TestPO0001").TableId;

this table method will provide us the file url
DocuRef.CompleteFikleName() - after getting file name we will save it to our temp table of ssrs report.

3. Now open SSRS report design in visual studio and add an image in report body or footer as per our requirement and set the Image source property to External and add the dataset field (File path) here in expression (fx) and deploy the report, now it will display in your report.
after set this property just build and deploy report and we will get the attached image to the ssrs report.

Regards
B K Sharma

Customer transaction automatic settlement for specific customer groups only

Hi Friends, Recently I come to the requirement of my company where I have to automatic settle the customer transaction for the speci...