Friday, August 6, 2021

x++ code to move files from one folder to another after processing business logic

 public void run()

{

    CommaTextIo     commaTextIo;

    container values;

      FolderName      sourceFolder = @"\\test\Source";

    FolderName      destinationFolder = @"\\test1\Archive";

    System.Array    files;

    int fileCount, i;

    Filename    filepath;

    Filename    filename;

    Filename    fileType;

    // code added by dilip on 8/1/2018

           // str         currentFile;    - Declared the cuurentFile and destinationFile in classDeclaration Method

            #File

         InteropPermission   interopPerm;

         FileIOPermission    filepermission;

         Set                 permissionSet;


            // code ended by dilip on 8/1/2018



    InventJournalTable  inventJournalTable;

    InventJournalTrans  inventJournalTrans;

    InventDim           inventDim;

    JournalCheckPost    journalCheckPost;

    InventJournalName   inventJournalName;

    InventBatch         inventBatch;


    boolean             isFirst;


    new InteropPermission(InteropKind::ClrInterop).assert();


    try

    {

        files = System.IO.Directory::GetFiles(sourceFolder);


        fileCount = files.get_Length();


        for(i = 0; i < fileCount; i++)

        {

            currentFile = files.GetValue(i);

            commaTextIo = new CommaTextIo(currentFile,'R');

            isFirst = true;


            values = commaTextIo.read();

            values = commaTextIo.read();


            ttsBegin;


            while(values != conNull())

            {

                if(isFirst)

                {

                    inventJournalTable.clear();


                    inventJournalName = InventJournalName::find(conPeek(values, 2));


                    if(!inventJournalName)

                    {

                        break;

                    }


                    inventJournalTable.initFromInventJournalName(inventJournalName);

                    inventJournalTable.insert();


                    isFirst = false;

                }


                inventJournalTrans.clear();


                inventJournalTrans.initFromInventJournalTable(inventJournalTable);

                inventJournalTrans.TransDate    = str2Date(conPeek(values, 4), 213);

                inventJournalTrans.ItemId       = conPeek(values, 5);

                inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));

                inventJournalTrans.Qty          = str2num(conPeek(values, 11));


                inventDim.InventColorId         = conPeek(values, 6);

                inventDim.InventSizeId          = conPeek(values, 7);

                inventDim.InventLocationId      = conPeek(values, 8);

                inventDim.InventSiteId          = conPeek(values, 9);

                inventDim.inventBatchId         = conPeek(values, 10);


                select firstOnly RecId from inventBatch

                    where inventBatch.inventBatchId ==  inventDim.inventBatchId

                    && inventBatch.itemId ==  inventJournalTrans.ItemId;


                if(!inventBatch.RecId)

            {

                   inventBatch.clear();


                  inventBatch.initValue();

                  inventBatch.itemId = inventJournalTrans.ItemId;

                  inventBatch.inventBatchId = inventDim.inventBatchId;

                  inventBatch.insert();

               }


                inventJournalTrans.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;


                  inventJournalTrans.setCostPrice('', inventJournalTrans.inventDim(),  inventJournalTrans.inventTableModuleInvent());


                inventJournalTrans.insert();


                values = commaTextIo.read();

                  inventJournalTable.NumOfLines += 1;

        inventJournalTable.update();

            }


            //if(inventJournalTable)

            //{

                //journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);

                //journalCheckPost.run();

            //}


            ttsCommit;


            [filepath, filename, fileType] = fileNameSplit(currentFile);


           // code added by dilip on 8/1/2018

             destinationFile = destinationFolder + "\\" + filename + fileType;


                permissionSet =  new Set(Types::Class);

                permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

                permissionSet.add(new FileIOPermission(destinationFile,'w'));

                permissionSet.add(new FileIOPermission(currentFile,'rw'));

                CodeAccessPermission::assertMultiple(permissionSet);


                    //copy the file from source folder to destination folder

                    WINAPIServer::copyFile(currentFile, destinationFile);


                    //delete the file from source folder

                    commaTextIo.finalize();

                    commaTextIo = null;

                    filepermission = new FileIOPermission(currentFile, 'w');

                    filepermission.demand();

                    System.IO.File::Delete(currentFile);

                    CodeAccessPermission::revertAssert();

        // code ended by dilip on 8/1/2018

        }

    }

    catch

    {

        error("Import process failed");

    }


    CodeAccessPermission::revertAssert();

}

Add , update and delete BOM lines using X++ job

Belo job is used to add, update and delete bom items 

Make sure the import file is .csv 




static void lanMassupdateBOMlines_2019(Args _args)

{

 CommaTextIo     commaTextIo;

    container values;

    FolderName      sourceFolder = @"C:\MassUpdate";


    System.Array    files;

    int fileCount, i, intdel, intadd;

    real BOMQty;

    Filename    filepath;

    Filename    filename;

    Filename    fileType;

    str         currentFile,itemgroup,colorid,sizeid,bomcolor,bomsize,action,flushprinciple;


        InventTable inventtable;

    BOMVersion bomVersion;

    BOM bom;


    BOMTable bomTable;

  ItemId itemID, bomitemID;

    InventDim           inventDim,inventdimnew,inventdimBOM;

    InventDimCombination inventdimcombination;


    boolean             isFirst, ignore;


    new InteropPermission(InteropKind::ClrInterop).assert();


    try

    {

        files = System.IO.Directory::GetFiles(sourceFolder);


        fileCount = files.get_Length();


        for(i = 0; i < fileCount; i++)

        {

            currentFile = files.GetValue(i);

            commaTextIo = new CommaTextIo(currentFile,'R');

            isFirst = true;


            values = commaTextIo.read();



            ttsBegin;


            while(values != conNull())

            {

    itemID = any2str(conPeek(values, 1));

                  itemgroup = any2str(conPeek(values, 2));

                // get Item master

                    inventtable = InventTable::find(itemID);

  colorid =  any2str(conPeek(values, 4));

                       sizeid =  any2str(conPeek(values, 5));

                             bomitemID = any2str(conPeek(values, 7));

                       bomcolor = any2str(conPeek(values, 8));

                              bomsize =  any2str(conPeek(values, 9));

                BOMQty = str2num(conPeek(values, 10));

                  flushprinciple = any2str(conPeek(values, 11));

                  action =  any2str(conPeek(values, 12));

                 if(colorid == 'ANY' && sizeid == 'ALL' && action == 'DELETE')

                   {

                                 // get list of BOM versions associated to the Item and Site 'CAC'

                  while select * from bomVersion

                      where bomVersion.itemId == inventtable.ItemId && bomVersion.Name like '*CA'


                  {


                          select forUpdate bom  where bom.BOMId == bomVersion.BOMId

                          && bom.ItemId == bomitemID;

                      if (bom)


                          {

                                 ttsBegin;

                                bom.delete();

                              intdel++;


                                ttsCommit;

                          }


                       }


                       }

                else

                       if(colorid != 'ANY' && sizeid == 'ALL' && action == 'DELETE')

                {

                             // get list of BOM versions associated to the Item and Site 'CAC'

                  while select * from bomVersion

                      where bomVersion.itemId == inventtable.ItemId && bomVersion.Name like '*CA'


                  {

                            select * from inventdim where inventDim.inventDimId == bomVersion.InventDimId;


                       //check if BOM line already exists on the BOM Version

                   //select * from bom where bom.ItemId == bomitemID && bom.BOMId == bomVersion.BOMId && bom.BOMQty == 1.02;


                  //  if(!bom)

                  //  {


                        // if no BOM exists create new BOM line



                       if(inventDim.InventColorId == colorid)


                       {


                          select forUpdate bom  where bom.BOMId == bomVersion.BOMId

                          && bom.ItemId == bomitemID;

                      if (bom)


                          {

                                 ttsBegin;

                                bom.delete();

                              intdel++;


                                ttsCommit;

                          }



                      }


                      }

                }


            if(colorid == 'ANY' && sizeid == 'ALL' && action == 'ADD')

                {


                      // get list of BOM versions associated to the Item and Site 'CAC'

                  while select * from bomVersion

                      where bomVersion.itemId == inventtable.ItemId && bomVersion.Name like '*CA'


                  {

                            select * from inventdim where inventDim.inventDimId == bomVersion.InventDimId;


                       //check if BOM line already exists on the BOM Version

                   select * from bom where bom.ItemId == bomitemID && bom.BOMId == bomVersion.BOMId

                   && bom.BOMQty == BOMQty;


                    if(!bom)

                    {


                        // if no BOM exists create new BOM line


                       if(inventDim.InventColorId == colorid || colorid == 'ANY')


                       {

                            bom.clear();

                            inventdimnew.clear();

                            bom.initValue();


                            bom.BOMId = bomVersion.BOMId;

                            bom.ItemId = bomitemID;

                            bom.BOMQty = str2num(conPeek(values, 10));

                            bom.OprNum = 0;

                            bom.UnitId = 'EA';

                            inventdimnew.InventColorId = bomcolor;

                            inventdimnew.InventSiteId = 'CAC';


                               if (bomsize == 'ALL')

                               {

                             inventdimnew.InventSizeId = inventDim.InventSizeId;

                               }

                               else

                               {

                                    inventdimnew.InventSizeId = bomsize;

                               }


                           // inventdimnew.InventLocationId =  inventDim.InventLocationId;

                            inventdimnew.InventLocationId =  'CA';


                            bom.InventDimId = InventDim::findOrCreate(inventdimnew).inventDimId;

                           if (flushprinciple == 'Manual')

                           {

                            bom.ProdFlushingPrincip = 1;

                           }

                           else

                           {

                              bom.ProdFlushingPrincip = 3;

                           }

                                // validate the BOM

                            if(bom.validateWrite())

                            {


                                 bom.insert();

                                 intadd++;


                            }

                            }

                      }

                      }

                    }

                    else


                    {


              if(colorid != 'ANY' && sizeid == 'ALL' && action == 'ADD' )

                {


                      // get list of BOM versions associated to the Item and Site 'CAC'

                  while select * from bomVersion

                      where bomVersion.itemId == inventtable.ItemId && bomVersion.Name like '*CA'


                  {

                            select * from inventdim where inventDim.inventDimId == bomVersion.InventDimId;


                       //check if BOM line already exists on the BOM Version

                 select * from bom where bom.ItemId == bomitemID && bom.BOMId == bomVersion.BOMId && bom.BOMQty == BOMQty;


                if(!bom)

                {


                        // if no BOM exists create new BOM line


                       if(inventDim.InventColorId == colorid)


                       {

                            bom.clear();

                            inventdimnew.clear();

                            bom.initValue();


                            bom.BOMId = bomVersion.BOMId;

                            bom.ItemId = bomitemID;

                            bom.BOMQty = str2num(conPeek(values, 10));

                            bom.OprNum = 0;

                            bom.UnitId = 'EA';

                            inventdimnew.InventColorId = bomcolor;

                            inventdimnew.InventSiteId = 'CAC';


                               if (bomsize == 'ALL')

                               {

                             inventdimnew.InventSizeId = inventDim.InventSizeId;

                               }

                               else

                               {

                                    inventdimnew.InventSizeId = bomsize;

                               }


                            //inventdimnew.InventLocationId =  inventDim.InventLocationId;

                           inventdimnew.InventLocationId =  'CA';

                            bom.InventDimId = InventDim::findOrCreate(inventdimnew).inventDimId;

                           if (flushprinciple == 'Manual')

                           {

                            bom.ProdFlushingPrincip = 1;

                           }

                           else

                           {

                              bom.ProdFlushingPrincip = 3;

                           }

                                // validate the BOM

                            if(bom.validateWrite())

                            {


                                 bom.insert();

                                 intadd++;

                            }

                            }


                      }

                     }


                   }


                }



                values = commaTextIo.read();


            }



            ttsCommit;

          //  Box::info("Success, Imported BOM lines for New Fit HangTag");

            [filepath, filename, fileType] = fileNameSplit(currentFile);


 info(strfmt("Total number of Boms deleted are - %1", intdel));

                 info(strfmt("Total number of BOMs added are - %1", intadd));

        }

    }

    catch

    {

        error("Import process failed");

    }


    CodeAccessPermission::revertAssert();

}

AX 2012 R3 - SSRS install

 


steps to install SSRS extensions:


- Install SQL server SSRS services first

- Using Reporting services configuration Manager, configure the reporting server, database and URL as shown below


Configure SQL Server Reporting Service 2016 (SSRS).

 Once the SSRS feature is installed successfully, you should configure it manually by doing the following:

Open Reporting Service Configuration Manager.



Connect to the Report Server Instance.



Review Report Server Status and make sure it's started.



In "Service Account", you will find the report server service account that runs the Report Server Service.



Go first to the "Database" section to configure the database that holds the all report server content and application data.



Note: in case you have deleted a report in reporting service, you can't restore it! the available options are

  • you have a copy of the deleted report on your local machine so you can upload it again.
  • you have a backup from the report database so you can restore it.

Click Change database to create the report server database for the first time.

Check Create a new report server database.



Make sure the database server is correct.

Set the authentication type as (Integrated User or SQL Server account). 

Note: this account must have permission to connect to the database server. 

Provide the correct account credentials.



Test the connection and make sure that the connection is established successfully.



Specify the database name as you prefer.



Specify the credentials of an existing account that the report server will use to connect to the report server database.



Review the summary information, and make sure that everything is set properly before proceeding.



Wait while the report server database wizard configures the database then click Finish.



Go back to configure the "Report Server Web Service URL".

  • Set the Report Server Web Service URL virtual directory.
  • Set the Report Server web service site identifications based on your requirements then click Apply.



Test the Report Server Web Service URL that should be now browsed properly.



Go now to the "Report Manager URL", specify the virtual directory as you prefer then click Apply to configure it.



Once the Report Manager Completed Successfully, Click the Report Manager URL to test it.



Great, it should be now browsed properly.


  Note

If you got a permission issue to access report manager, please check SSRS 2016: You are not allowed to view this folder. Contact your administrator to obtain the necessary permissions. Jump Jump

Go now to the "Encryption keys".



Take a backup of the symmetric key that used to encrypt sensitive data in the report server database like connection strings, credentials ...etc. it will be helpful in case you migrate or move the report server installation to another server, you can restore this key to regain access to the encrypted content.



 

 


Sunday, January 10, 2021

Object Oriented Programming CONCEPT IN D365

 What is OOPS?

Object Oriented Programming is a programming concept that works on the principle that objects are the most important part of your program. It allows users create the objects that they want and then create methods to handle those objects. Manipulating these objects to get results is the goal of Object Oriented Programming.
Object Oriented Programming popularly known as OOP, is used in a modern programming language.

Core OOPS concepts are

1) ClassThe class is a group of similar entities. It is only an logical component and not the physical entity. For example, if you had a class called “Expensive Cars” it could have objects like Mercedes, BMW, , etc. Its properties(data) can be price or speed of these cars. While the methods may be performed with these cars are driving, reverse, braking etc.
2) Object
An object can be defined as an instance of a class, and there can be multiple instances of a class in a program. An Object contains both the data and the function, which operates on the data. For example - chair, bike, marker, table, car, etc.
3) Inheritance
Inheritance is an OOPS concept in which one object acquires the properties and behaviors of the parent object. It’s creating a parent-child relationship between two classes. It offers robust and natural mechanism for organizing and structure of any software.
4) Polymorphism
Polymorphism refers to the ability of a variable, object or function to take on multiple forms. For example, in English, the verb “run” has a different meaning if you use it with “a laptop,” “a foot race, and ”business. Here, we understand the meaning of “run” based on the other words used along with it.The same also applied to Polymorphism.
5) Abstraction
An abstraction is an act of representing essential features without including background details. It is a technique of creating a new data type that is suited for a specific application. For example, while driving a car, you do not have to be concerned with its internal working. Here you just need to concern about parts like steering wheel, Gears, etc.
6) Encapsulation
Encapsulation is an OOP technique of wrapping the data and code. In this OOPS concept, the variables of a class are always hidden from other classes. It can only be accessed using the methods of their current class. For example - in school, a student cannot exist without a class.
7) Association
Association is a relationship between two objects. It defines the diversity between objects. In this OOP concept, all object have their separate lifecycle, and there is no owner. For example, many students can associate with one teacher while one student can also associate with multiple teachers.
8) Aggregation
In this technique, all objects have their separate lifecycle. However, there is ownership such that child object can’t belong to another parent object. For example consider class/objects department and teacher. Here, a single teacher can’t belong to multiple departments, but even if we delete the department, the teacher object will never be destroyed.
9) Composition
A composition is a specialized form of Aggregation. It is also called "death" relationship. Child objects do not have their lifecycle so when parent object deletes all child object will also delete automatically. For that, let’s take an example of House and rooms. Any house can have several rooms. One room can’t become part of two different houses. So, if you delete the house room will also be deleted.

Advantages of OOPS:

  • OOP offers easy to understand and a clear modular structure for programs.
  • Objects created for Object-Oriented Programs can be reused in other programs. Thus it saves significant development cost.
  • Large programs are difficult to write, but if the development and designing team follow OOPS concept then they can better design with minimum flaws.
  • It also enhances program modularity because every object exists independently.

DATABASE SYNCHRONIZATON IN D365

 


 HOW TO SYNCHRONIZE DATABASE IN D365


There are multiple ways to synchronize database in dynamics 365 fno.

1) FULL synchronization


You should always do full synchronization in case you have the below points.
a) any updates
b) after get latest
c) any major customization import.
However this should also be done along with the builds of the model.

As shown in the below screenshot.
Select Dynamics 365 > Build Models > 

DATABASE SYNCHRONIZATON IN D365,db sync in d365,database syncronisation with build,build and database sync in d365,ax 2012 synchronize database,



for Full build you can click on Synchronize database and then click synchronize.
However I would suggest you to click on Full build and then on the other tab Options select Synchronize database.

build in d365,DATABASE SYNCHRONIZATON IN D365,db sync in d365,database syncronisation with build,build and database sync in d365,ax 2012 synchronize database,


Now click on Options and select Sync


 Now click BUILD.


2)Synchronization only database

you can just sync database with the below option.

select sync database and select sync.

SYNC DB WITH PROJECT BUILD.
SET THE PROPERTIES OF THE SYNC DATABASE IN THE SOLUTION EXPLORER TO YES AS HSOWN BELOW.