Friday 29 July 2016

Using/Extending SysOperationFramework instead of RunBaseFramework in AX 2012

Below are the Classes created to Demonstrate
 

1.  ESS_DemoSysOperationController Class which extends SysOperationServiceController – (For Batch Dialog)
2.  ESS_DemoSysOperationService Class which extends SysOperationServiceBase – (For multitask Batch Initiation)
3.  ESS_DemoOperationDataContract Class – (For parameter values)
4.  ESS_DemoSysOperationTaskService Class – (For actual logic to execute in Batch)

1.   Create a class extends SysOperationServiceController
    class ESS_DemoSysOperationController extends SysOperationServiceController
    {

}

    a.   Override new method
       protected void new()
       {
            super(classStr(ESS_DemoSysOperationService), methodStr(ESS_DemoSysOperationService, update),   SysOperationExecutionMode::Synchronous);
       }

b.   Create  Construct method
        server static ESS_DemoSysOperationController construct()
        {

    ESS_DemoSysOperationController      controller; 

    controller = new ESS_DemoSysOperationController ();

    controller.parmShowDialog(true); // Actually the default value

    controller.parmShowProgressForm(false);

    return controller;
        }

c.   Create main method

static void main(Args args)
        {

    ESS_DemoSysOperationController operation;
            operation = new ESS_DemoSysOperationController ();
            operation.startOperation();
        }

2.   Create a class extends SysOperationServiceBase

class ESS_DemoSysOperationService extends SysOperationServiceBase
    {

    BatchHeader                         batchHeader;
        SysOperationServiceController       controller;
        ESS_DemoSysOperationDataContract    contract;
    }

 

a.   Create update method

[SysEntryPointAttribute]
    public void update()
    {

    RefRecId minRecId, maxRecId, fromRecId, toRecId;
        minRecId =  5637775244;
        maxRecId =  5648390004;
        fromRecId = minRecId;

    if(this.isExecutingInBatch())
        {
            if(!batchHeader)
            {
                 batchHeader = BatchHeader::getCurrentBatchHeader();
            }

        while (toRecId < maxRecId)
            {
                 toRecId = fromRecId + 100000;

            // Create a service controller to run the task
            controller = new SysOperationServiceController(classStr(ESS_DemoSysOperationTaskService), methodStr(ESS_DemoSysOperationTaskService, insertRecords),SysOperationExecutionMode::Synchronous);

        contract = controller.getDataContractObject();
            contract.parmValues(["value01", "value02",fromRecId,toRecId]);
            batchHeader.addRuntimeTask(controller, this.getCurrentBatchTask().RecId); // Create a runTimeTask within the current batch job
           fromRecId = toRecId;
        }
    }
    else
    {
        // Create a service controller to run the task
        controller = new SysOperationServiceController(classStr(ESS_DemoSysOperationTaskService), methodStr(ESS_DemoSysOperationTaskService, insertRecords),SysOperationExecutionMode::Synchronous);

        contract = controller.getDataContractObject();
        contract.parmValues(["value01", "value02",minRecId,maxRecId]);
        controller.run();
  
    }
    // If we're processing in batch, then save the batch header
    if(batchHeader)
    {
        batchHeader.save();
    }
}

3.   Create a Class ESS_DemoSysOperationDataContract

[DataContractAttribute]
    public class ESS_DemoSysOperationDataContract
    {
         container   conValues;
    }

a.   Create parmValues method

[DataMemberAttribute]
        public container parmValues(container _values = conValues)
        {
             conValues = _values;
         
             return conValues;
        }

 
4.   Create a Class ESS_DemoSysOperationTaskService
 
     public class ESS_DemoSysOperationTaskService
     {
         ESS_SysOperationDemoTable       ess_SysOperationDemoTable;
     }

a.   Create insertRecords method

[SysEntryPointAttribute]
        public insertRecords(ESS_DemoSysOperationDataContract _contract)
        {
            str                         value01, value02;
            RefRecId            fromRecId, toRecId;    
            RecordInsertList     recordInsertList = new RecordInsertList(tableNum(ESS_SysOperationDemoTable));

    [value01, value02, fromRecId, toRecId] = _contract.parmValues();

    While (condition)
            {
                 ess_SysOperationDemoTable.clear();
                 ess_SysOperationDemoTable.Field01 = 1
                 ess_SysOperationDemoTable.Field02 = 2;
                 recordInsertList.add(ess_SysOperationDemoTable);
            }
       
            recordInsertList.insertDatabase();
        }

Older SQL Backup files deletion through batch


To keep backup files up to 30 days and delete rest of the files in Windows Batch:

Create a batch file using the below command:

forfiles /M *.bak /P "Backup Folder" /S /D -NoOfDays /C "cmd /c del /F /Q @path"

forfiles /M *.bak /P "E:\SQL Backup" /S /D -30 /C "cmd /c del /F /Q @path"

Copy paste the below command in notepad and change your folder path and Days then Save as .bak file.

Refer below link for further:


Use the Windows Task Scheduler to call the batch script:
https://technet.microsoft.com/en-us/library/cc748993(v=ws.11).aspx

Monday 27 June 2016

AX7 - How to get recent modifications/changes in application



1.       To count particular of objects in a model:

[System.IO.Directory]::GetFiles("C:\Packages\ESS_WBS\ESS_WBS\AxClass\","*.xml").count

 
 
 

2.       To get list of objects modified in past 120 days:

Get-ChildItem -Path "C:\Packages\*" -Recurse -Include *.xml |select LastWriteTime, FullName,Name| Where{$_.LastWriteTime –ge (Get-Date).addDays(-120)} |Sort-Object lastWriteTime -descending| out-gridview

 
 

Sunday 15 May 2016

Get Department Financial Dimension Value


  • To get Department financial dimension value from Journal Transactions (LedgerJournalTrans)
// BP Deviation Documented
public display OMOperatingUnitNumber sha_displayDepartment()
{

    DimensionAttribute                  dimAttribute = DimensionAttribute::findByName('Department'); // Change 'Department' to which dimension you are looking for
    DimensionAttributeValueSetItemView  dimAttributeValueSetItemView;

    select firstOnly dimAttributeValueSetItemView
        where dimAttributeValueSetItemView.DimensionAttributeValueSet == this.DefaultDimension &&
              dimAttributeValueSetItemView.DimensionAttribute == dimAttribute.RecId;
   
    return dimAttributeValueSetItemView.DisplayValue;
}



  • To get Department financial dimension value from Voucher Transactions (GeneralJournalAccountEntry)

 
// BP Deviation Documented
public display OMOperatingUnitNumber sha_displayDepartment()
{
    DimensionAttribute                  dimAttribute = DimensionAttribute::findByName('Department'); // Change 'Department' to which dimension you are looking for
    DimensionAttributeLevelValueAllView dimAttributeLevelValueAllView;
   
   
    select firstOnly dimAttributeLevelValueAllView
        where dimAttributeLevelValueAllView.ValueCombinationRecId == this.LedgerDimension &&
              dimAttributeLevelValueAllView.DimensionAttribute == dimAttribute.RecId;
   
    return dimAttributeLevelValueAllView.DisplayValue;
}

Saturday 9 April 2016

AX 7 Form Event Handlers


We must use Event handlers, if you are using Extension Model Development in AX 7.

1. How we can handle the Datasource fields based on active/selected record, in Event handler method.

[FormDataSourceEventHandler(formDataSourceStr(FormName, DataSource), FormDataSourceEventType::Activated)]
public static void DataSource_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
    Common    common = sender.cursor();
    sender.object(fieldNum(DataSource, ProjActivityNumber)).enable(common.ProjId);
}

2. How we can handle the Controls like, Tab/TabPage/Button etc
 
[PostHandlerFor(formStr(
LedgerJournalTable), formMethodStr(LedgerJournalTable, init))]
    public static void LedgerJournalTable_Post_init(XppPrePostArgs args)
    {
        FormRun             sender = args.getThis();
        LedgerJournalType   journalType = sender.args().parmEnum();

        if (journalType == LedgerJournalType::Assets)
        {
            sender.control(sender.controlId(formControlStr(LedgerJournalTable, YourControl))).visible (true);
        }
 
3. To get new number sequence reference for an existing module.
 
 
    [PostHandlerFor(formStr(AssetParameters), formMethodStr(AssetParameters, numberSeqPreInit))]
    public static void AssetParameters_Post_numberSeqPreInit(XppPrePostArgs args)
    {
        TmpIdRef                                tmpIdRef;
        NumberSeqScope                          scope;
        NumberSeqApplicationModule              numberSeqApplicationModule;
        container                               numberSequenceModules;
 
        numberSequenceModules = [NumberSeqModule::Asset];
        numberSeqApplicationModule = new NumberSeqModuleAsset_XXX();
        scope = NumberSeqScopeFactory::createDataAreaScope();
        NumberSeqApplicationModule::createReferencesMulti(numberSequenceModules, scope);
        tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(numberSequenceModules));
 
        args.setArg('tmpIdRef',tmpIdRef);
    }
 
 
 

 
 

Label editor in AX 7

We have Lookup Label/Text option in earlier versions of AX in X++ Code Editor.
We don’t have exact option in AX 7. Use label search short cut (Ctrl-R, Ctrl-L).

Saturday 30 January 2016

Setup AX7 VM on Oracle Virtual Box


        Go through the below link to get idea on AX7 VM running on Premises
        https://ax.help.dynamics.com/en/wiki/access-microsoft-dynamics-ax-7-instances-2/
  • Extract the downloaded VM files. Downloaded VM files size around 20 GB. After extraction VHD file size around 120 GB. So make sure that you have enough space in your local hard drive.


  • Create new virtual machine as shown below. Use an existing virtual hard disk and attached the extracted VHD file.

  • Do the settings as shown below.



  • Start AX7 VM.
  • Login with contoso\administrator.
  • If it asks for the Network connection to be used. Click YES
  • Then set the static ip address for the VM.
  • Go to the approot folder.

  •      Take the backup of Web.config file and open the file with notepad search for the 127.0.0.1
    With the new IP we have assigned above.

  • Open the hosts file with notepad from the below shown path and replace 127.0.0.1 with the new IP we have assigned above.
  • Then go to the services and check DynamicsAXBatch is in running state, if not start the service.




  • Sometimes you may get the below 500 Error, that is because of the local system Time zone, Date & time are not matching with the VM. Change the Date & Time Settings accordingly then you will be able to login to AX.

  • Finally able to login AX 7… :)

Monday 18 January 2016

Dynamics AX 7 Look & Feel

   AX 7 Screen 




   Highlighted with the numbers... as follow

  1.    Search Option
  2.    Company which we logged in
  3.    Alerts for the current user
  4.    Settings
  5.    Help
  6.    Company Banner
  7.    Calendar
  8.    Work space
  9.    Workflows assigned
  10.    Main Menu
    1. Search Option:
     This is very useful option, if you are not aware of the particular menuitem in which Work           space/Module available.
   


 2. Company:
     Can see the list of companies available & can change the company.



3. Alerts:
     Can see the list of alerts raised for the current user.

4. Settings:
     Can update the user options, can start Task recorder. Can see the version of application with      option About.

5. Help:
    Help guide for the particular task. 



6. Company banner:
    Company banner is different from Company logo. Can differentiate the logged in entity by         selecting different banner easily. 
7. Calendar:
    Can change the session date using calendar. In below screenshot highlighted date is Session       date & only rounded date is System date.


8. Work space:
    Work spaces are useful for the segregation of the functionality/operations. We can assign          work spaces to the users. It gives the dash board experience like Enterprise Portal dash            boards in older versions of AX.
9. Work flows assigned:
    Can see the workflows assigned to the current logged in user.


10. Main Menu:
    Can see module list from here.


Enjoy... :)