Tuesday, December 26, 2023

Sys Operation Framework in D-365 ??


Sys Operation Framework in D-365 ??


First, what are some scenarios where you might want a process or job to run in the background?

The most common scenario is that you have a set of records that you need to process or do some calculation for. Perhaps you have used a Data Entity or Service to bring data into a staging table. Now you need to loop through each record and create functional data inside the system. SysOperation Framework in D365 is made for just this sort of thing.

Another scenario is that you have some process that you normally run on a single record in a form, but now you want to run the process on many records. SysOperation Framework in D365 can easily be setup to loop through a group of records and call existing code to process each record.

Lastly, is a scenario that is often under used. You may have a button on a form that when clicked will run some process on a record. If that process does not run instantly and you do not need to immediately use the result of the process, you can offload that work to job that uses SysOperation Framework in D365. Perhaps running a single process only takes 15 seconds to run, but by letting the system do the work in the background you can improve the user experience greatly. Typically a user would have to wait those 15 seconds while the operation completes. But now they are given back control immediately and can continue working.

Create The Contract

The contract class defines the parameters that will be passed to the service class for processing. In this example, let's assume we want to update customer group.

[DataContract]

Public class  WRE_SCPCustGroupChangeContract  extends SysOperationDataContractBase

{

       CustAccount     custNum;

       CustGroupId     custGroup;

   [DataMember]

     public CustAccount custNum(CustAccount _custNum = custNum)

       {

          custNum = _custNum;

           return custNum;

       }

   [DataMember]

    public CustGroupId custGroup(CustGroupId _custGroup = custGroup)

       {

           custGroup = _custGroup;

            return custGroup;

       }


}


 Service Class :

The service class contains the business logic for processing the batch operation.


public class WRE_SCPCustGroupChange

{

   CustAccount custNum;

   CustGroupId custGroup;

   protected void InitFromContract(WRE_SCPCustGroupChangeContract  _contract)

   {

      custNum = _contract.custNum();

      custGroup = _contract.custGroup();

   }

   protected void UpdateCustGroup()

   {

       CustTable cust = CustTable::Find(custNum, true);

       if (cust.RecId != 0)

       {

           cust.CustGroup = custGroup; cust.update();


       }


   }


   public void Run( WRE_SCPCustGroupChangeContract _contract)

   {

       this.InitFromContract(  _contract);

       ttsbegin;

       this.UpdateCustGroup();

       ttscommit;


   }

}

Create Controller class:

The controller class is responsible for initiating the batch operation by creating an instance of the service class and passing the contract parameters.


public  class WRE_SCPCustGroupChangeController extends SysOperationServiceController

{

   public static void main(Args _args)

   {

       WRE_SCPCustGroupChangeController controller;

       controller = new WRE_SCPCustGroupChangeController(classStr(WRE_SCPCustGroupChange),methodStr(WRE_SCPCustGroupChange, Run),

         SysOperationExecutionMode::Synchronous);

       controller.parmDialogCaption("Change Customer Group");

       controller.startOperation();

   }


}


Create new Action Menu iteam  






Open Account Receivable 


look at customer Group Number Required  to  change the 90 -to -10 



Open the Account Receivable Action Menu I team open look at above page parameters like that customer group 90 to change -10 customer account like same click OK



Open customer id -DE-001 - customer group-10 changes Done 
    

 





Sunday, December 24, 2023

How to Import Records from Excel Using X++ Code in ...

 

How to Import & Export Records from Excel Using X++ Code in ...

  

Note:Form to Excel import and Export Data 

1.create Runnable Class(Job)---Import code

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;
 
class WRE_importDtainExa
{
   public static void main(Args _args)
   {
       WRE_Test                    test;
       System.IO.Stream            stream;
       ExcelSpreadsheetName        sheeet;
       FileUploadBuild             fileUpload;
       DialogGroup                 dlgUploadGroup;
       FileUploadBuild             fileUploadBuild;
       FormBuildControl            formBuildControl;
       Dialog                      dialog = new Dialog("Import the data from Excel");
 
 
       dlgUploadGroup          = dialog.addGroup("@SYS54759");
       formBuildControl        = dialog.formBuildDesign().control(dlgUploadGroup.name());
       fileUploadBuild         = formBuildControl.addControlEx(classstr(FileUpload), "Upload");
       fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
       fileUploadBuild.fileTypesAccepted(".xlsx");
 
       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;
                   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;
 
                   for (i = 2; i<= rowCount; i++)
                   {
                       test.CustomerName = range.get_Item(i, 1).value;
                       test.CustomerAccount = range.get_Item(i, 2).value;
                       test.insert();
 
 
                       info(range.get_Item(i, 1).value);
                       info(range.get_Item(i, 2).value);
                   }
               }
           }
           else
           {
               error("Error here");
           }
 
       }
   }
 
}



2.create Runnable Class(Job)---Export code

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
using System.IO.MemoryStream;
 
class WRE_ExcelExportClass
{
   public static void main(Args _args)
 
   {
       WRE_ExportExcelTable              vendTable;
      
       Taxregistration                   taxregistration;
       MemoryStream   memoryStream = new MemoryStream();
 
       DocuFileSaveResult saveResult = DocuFileSave::promptForSaveLocation("@ApplicationPlatform:Testingexcelexport", "xlsx", null, "Testing excel export");
       if (saveResult && saveResult.parmAction() != DocuFileSaveAction::Cancel)
       {
           saveResult.parmOpenParameters('web=1');
           saveResult.parmOpenInNewWindow(false);
           System.IO.Stream workbookStream = new System.IO.MemoryStream();
          // System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
     
           using (var package = new ExcelPackage(memoryStream))
           {
 
               var currentRow=1;
               var worksheets = package.get_Workbook().get_Worksheets();
               var worksheet = worksheets.Add("First sheet");
               var cells = worksheet.get_Cells();
 
               var cell = cells.get_Item(currentRow,1);
               System.String value="CustomerName";
               cell.set_Value(value);
 
               cell=null;
               value="CustomerAccount";
               cell=cells.get_Item(currentRow,2);
               cell.set_Value(value);
 
               cell=null;
               value="CustomerMobileNo";
               cell=cells.get_Item(currentRow,3);
               cell.set_Value(value);
         
 
               while select vendTable
               {
                   currentRow ++;                cell = null;
                   cell = cells.get_Item(currentRow,1);
                   cell.set_Value(vendTable.CustomerName);
                   cell = null;
                   cell = cells.get_Item(currentRow, 2);
                   cell.set_Value(vendTable.CustomerAccount);
                   cell = null;
                   cell = cells.get_Item(currentRow, 3);
                   cell.set_Value(vendTable.CustomerMobileNo);
               }
               package.Save();
               memoryStream.Seek(0, System.IO.SeekOrigin::Begin);
               DocuFileSave::processSaveResult(memoryStream, saveResult);
           }
       }
   }
   
 
}










QR Code & BarCode generator in D 365 F&O x++

 How To create QR Code in Report ?


1.write  a contract class like below Exp!


[DataContractAttribute]

Public class QRCodeCreationContract

{

   CustomerNameEDT   customerName;

 

   [DataMemberAttribute]

   public str parmCustomerName(str _customerName = customerName)

   {

       customerName = _customerName;

       return  customerName;

   }

 

}


2.Write a Dp class ?


[SRSReportParameterAttribute(classStr(QRCodeCreationContract))]

public class QRCodeCreationDp extends  SRSReportDataProviderBase

{

   WRE_QRCodeCreationTempTable       qRCodeCreationtemp;

 

   CustomerNameEDT      CustomerName;

 

 

   [SRSReportDataSetAttribute(tableStr('WRE_QRCodeCreationTempTable'))]

   public WRE_QRCodeCreationTempTable   getqRCodeCreationtemp()

   {

       select  qRCodeCreationtemp;

       return  qRCodeCreationtemp;

   }

 

   public static container QRCode(Str _QRContents)

   {

       // QRContents is a formatted string provided as input to this function.

       // For example _QRContents= ?name='Customer name'&rr='RFCno'&tt='totalInvoiceAmount';

 

       System.Drawing.Bitmap bm = null;

       try

       {

           //var qrCodeEncoder = new Encoder();

           Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder qrCodeEncoder = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

           bm = qrCodeEncoder.Encode(_QRContents);

       }

       catch (Exception::CLRError)

       {

           error(CLRInterop::getLastException().ToString());

       }

       using (var stream = new System.IO.MemoryStream())

       {

           bm.Save(stream, System.Drawing.Imaging.ImageFormat::Bmp);

           bm.Dispose();

           return Binary::constructFromMemoryStream(stream).getContainer();

       }

   }

 

   public void processReport()

   {

      

       WRE_QRCodeCreationTable                  qrcodecreationTable;

       CompanyInfo                                          companyinfo;

                                                       

       companyinfo =  CompanyInfo::find();

 

       Query                                      query   = new Query();

       QueryBuildDataSource           qbds1;

       QueryBuildRange                    qbr;

       QueryRun                                qRun;

                                      

       QRCodeCreationContract       contract;

       contract = this.parmDataContract();

       customerName = contract.parmCustomerName();

 

       qbds1 = query.addDataSource(tableNum(WRE_QRCodeCreationTable));

       qbr   = qbds1.addrange(fieldNum(WRE_QRCodeCreationTable, CustomerName));

       qbr.value(CustomerName);

 

      

       qRun = new QueryRun(query);

       while(qRun.next())

       {

           

           qrcodecreationTable            = qRun.get(tableNum(WRE_QRCodeCreationTable));

         

           //qRCodeCreationtemp.clear();

           

         

           qRCodeCreationtemp.QRCode           = AA_CreateBarcodeHelper::generateQRCodeFromBase64(qrcodecreationTable.CustomerID);

           qRCodeCreationtemp.CustomerAddress  = qrcodecreationTable.CustomerAddress;

           qRCodeCreationtemp.CustomerID           = qrcodecreationTable.CustomerID;

           qRCodeCreationtemp.CustomerName     = qrcodecreationTable.CustomerName;

           qRCodeCreationtemp.CustomerMobileNo = qrcodecreationTable.CustomerMobileNo;

           qRCodeCreationtemp.BarCode          = AA_CreateBarcodeHelper::showBarcode(qrcodecreationTable.CustomerName);

           qRCodeCreationtemp.CurrentDate      = today();

           

           

           qRCodeCreationtemp.insert();

 

       }

   }

 

}


3.Create A  New Class   AA_CreateBarcodeHelper (For QRCode&BarCode)

class AA_CreateBarcodeHelper

{

   /// <summary>

   /// Barcode creation

   /// </summary>

   /// <param name = "barcodeText">Pass the text that you want to scan while scanning Bar Code</param>

   /// <returns>Barcode</returns>

   public static BarCodeString showBarcode(str barcodeText)

   {

       Barcode barcode;

 

 

       barcode = Barcode::construct(BarcodeType::Code39);

       barcode.string(true, barcodeText);

       barcode.encode();

 

 

       return barcode.barcodeStr();

   }

 

   public static Bitmap generateQRCodeFromBase64(str qrCodeText)

   {

       Bitmap qrCode;

 

 

       EFDocQRCode_BR generateQR = new EFDocQRCode_BR();

       generateQR.parmErrorCorrectionLevel(QRCodeErrorCorrectionLevel::Medium);

 

 

       try

       {

           qrCode = generateQR.generateQRCode(qrCodeText);

       }

       catch (Exception::CLRError)

       {

           warning("@ApplicationSuite_Localization:QRCodeIsDamaged");

       }

 

 

       return qrCode;

   }

 

}


4.Create Report Design As per Your Requirement ??


  QR CODE 

  




What you need to do?

  1. Create two simple classes, one is for QR code creation helper and other is for Bar code generation helper and paste the below code in it.
  2. Now, you can use these classes where you need to add the bar code or Qr code by simply calling it.

1. Create a new field in tmp table of the SSRS report

Field type: Extends
Extends: Bitmap
TmpTableQRCodeBitmap




  1. 2. Call above created function in DP class

    Provide formatted string for which QR code needs to be created and
    populate the tmp.QRCode =QRHelper::QRCode(_FormattedString)



  1. 3. Insert Image in RDLC design part of SSRS ??

  2. QRCodeImageRDLC


  1. 4.Build the project and deploy the report

    The report is now generated with a QR code.
    QRCodeSSRS


How To Create A WorkFlow In D365F&O

  How To Create Work Flow In D-365 F&O ? What is workflow? A workflow in the dynamics 365 apps is a way that automate business processes...