Showing posts with label AX2012. Show all posts
Showing posts with label AX2012. Show all posts

Multi-thread Imports in Dynamics 365 for Finance & Operations

  

Multi-thread Imports in Dynamics 365 for Finance & Operations


There are a few perplexities on how to multi-thread your imports in Dynamics 365 for Finance and Operations. The primary thing to know is that Microsoft prevents you from multi-threading a few entities, which may be a great thing. Usually great since in Flow AX 2012 you'll multi-thread any substance and fundamentally, in case the arrange of the records getting imported is critical, at that point, multi-threading isn’t a great alternative since in case they go out of grouping due to records getting imported in parallel you'll degenerate your data.

The moment the thing to know is how to set up multi-threading in Dynamics 365FO. To do this you essentially go to Workspaces > Information Administration > Tap the System Parameters tile > Substance Settings tab > Press Arrange Substance Execution Parameters.



Within the entity execution parameters, you're defining how numerous strings ought to be utilized after you purport a substance in the group. You wish to get it merely can set up a substance at different times in this frame as seen below.





You're defining three things within the form:

Entity – What substance are you setting multi-threading up for.

Import threshold– The threshold tells the framework how numerous records got to be imported to utilize this line.

Import record count – How numerous strings ought to be utilized; aka how numerous assignments are created. Example Let’s walk through an illustration of bringing in the “Customer Definition” substance with 1360 records.

Next Actions

Create Import project, add the entity you added earlier in the execution parameters form, and import in the batch mode.


To verify multi threading go to the Batch job screen, find your job and check in the view task screen, you will find multiple threads of your task.


Access Fields In A Table Using This Field Id

 




How To Access Field In A Table Using This Field Id

To do this you could use the next construction:

vendTable.( filednum( vendTable, VendAccount ) ) = “XXX”;

This is the same as

vendTable.VendAccount = “XXX”;

Example:

Field VendAccount from VendTable has id 1. Then statement VendTable.(1) = “V-00014” – will initialize field VendAccount with value “V-00014”.

You could also use this feature while working with records of type Common.

Example:

    Common      common;
    VendTable    vendTable;
    ;
    select vendTablewhere vendTable.VendAccount== "V-00014";
common = vendTable;
info( common.( fieldnum( vendTable
, VATNum) ) );


Customer Address book relation for channel Database D365FO


Customer Address book relation for channel Database D365FO



Scenario:

Most of our D365FO Fellow are working with Retail where we sync customer with our channel database, and sometime we need to update the customer from POS as well, Sometime channel DB throw exception when while updating the customer information if AddressBook of the customer  customer is not properly set.

Its happens when we create customer using AX client or import them via DMF and didn't set the address book value.


So no need to worry using below code & query you can update the customers address book in bulk.

Image:




Code:

public void AddrssBookRelation()
    {
        DirAddressBookParty       dirAddressBookParty;
        DirAddressBook                   dirAddressBook;
        CustTable                              custTable;


        select RecId,Party from custTable
            where custTable.AccountNum==this.CustomerAccount;

        if(custTable)
        {
            select RecId from dirAddressBook
            where dirAddressBook.Name==this.CountryCode;

            if(dirAddressBook)
            {
                select RecId from dirAddressBookParty
                    where dirAddressBookParty.Party==custTable.Party && dirAddressBookParty.AddressBook==dirAddressBook.RecId;

                if(dirAddressBookParty.RecId==0)
                {
                    dirAddressBookParty.clear();
                    dirAddressBookParty.Party=custTable.Party;
                    dirAddressBookParty.AddressBook=dirAddressBook.RecId;
                    dirAddressBookParty.insert();
                }

            }
        }

    }



SQL Query:

INSERT INTO DirAddressBookParty (PARTY,ADDRESSBOOK,PARTITION)
select DISTINCT DirPartyLocation.PARTY,DirAddressBook.RECID,5637144576 from LogisticsPostalAddress
join DirPartyLocation on DirPartyLocation.LOCATION=LogisticsPostalAddress.LOCATION
Join LOGISTICSLOCATION on LOGISTICSLOCATION.RECID=LogisticsPostalAddress.LOCATION
join DirAddressBook on DirAddressBook.NAME=LogisticsPostalAddress.COUNTRYREGIONID
where DirPartyLocation.ISPRIMARY=1 and party in (select party from CUSTTABLE)
and LOGISTICSLOCATION.ISPOSTALADDRESS=1 and DirPartyLocation.ISPOSTALADDRESS=1 and DirPartyLocation.POSTALADDRESSROLES='Business'
and not exists (select 1 from DirAddressBookParty where DirAddressBookParty.PARTY=DirPartyLocation.PARTY and DirAddressBookParty.ADDRESSBOOK=DirAddressBook.RECID)
 and LogisticsPostalAddress.VALIDTO >=GETDate()

Project Item Journal D365FO


Project Item Journal D365FO

Dynamics technical consultants often times receive the requirements to create the journal using X++ where we couldn't use data entity for any reason.

So, In this article, I am writing the sample which may help you a lot to create a project Item journal easily.





public void createProjectInventJournal(ProjectJournalContract    _projectJournal)
    {
        InventDim                            inventDim;
        InventJournalName                    InventJournalName;
        InventJournalTable                   inventJournalTable;
        InventJournalTableData               journalTableData = JournalTableData::newTable(inventJournalTable);
        InventTable                          inventTable;
        ProjTable                               projTable;
        AWCFieldServIntegrtionMainAccount     ServiceOffsetAccount=this.findServiceMainAccount(AWCFieldServiceIntegrationType::ProjectItem);
       
         ProjectJournalTransContract  journalTransContract;

        if(_projectJournal.getProjectJournalTransCount()==0)
        {
            return;
        }
       

        journalTransContract = _projectJournal.getProjectJournalTrans(0);

        select projTable
            where projTable.ProjId==journalTransContract.ProjectId;

        select inventTable
            where inventTable.itemId==journalTransContract.ItemId;

        select InventJournalName
            where InventJournalName.JournalType==InventJournalType::project
        && InventJournalName.isFSJournal==NoYes::Yes;

        inventJournalTable.JournalId = journalTableData.nextJournalId();
        inventJournalTable.JournalType=InventJournalType::project;
      
        journalTableData.initFromJournalName(InventJournalName);
     
        inventJournalTable.insert();

        InventJournalTrans          inventJournalTrans;
        InventJournalTransData      journalTransData = journalTableData.journalStatic().newJournalTransData(inventJournalTrans, journalTableData);
        journalTransData.initFromJournalTable();

        inventJournalTrans.TransDate    = today();

       

        inventJournalTrans.ProjId               =journalTransContract.ProjectId;
       inventJournalTrans.ProjCategoryId       = journalTransContract.ProjectCateId;
        inventJournalTrans.initFromProjTable(projTable);

        inventJournalTrans.initFromInventTable(inventTable);
       
        inventJournalTrans.Qty              = journalTransContract.QtyUsed;
        inventJournalTrans.PriceUnit        = journalTransContract.CostPrice;
     
        inventJournalTrans.ProjUnitID       = journalTransContract.Unit;
        inventJournalTrans.Worker           = HcmWorkerLookup::currentWorker();
        inventJournalTrans.LedgerDimension  = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(ServiceOffsetAccount.MainAccountId).RecId);
        inventJournalTrans.activityNumberModified();
        inventDim.clear();
        inventDim.InventSiteId  = journalTransContract.Site;
        inventDim.InventLocationId =journalTransContract.Location;
        inventDim.wMSLocationId = journalTransContract.Warehouse;

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

        //other fields
        journalTransData.create();
    }

Currency Conversion X++ AX7, D365FO and AX-2012


Currency Conversion X++ AX7, D365FO and AX-2012


Convert currency to currency.


Static void main(Args args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    AmountMst amountMST;
    CurrencyCode toCurrency =  ‘AED’;
    CurrencyCode FromCurrency =  ‘USD’;

    AmountCur amountCur = 5000;



        currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
        amountMST =  currencyExchangeHelper.calculateCurrencyToCurrency(toCurrency, fromCurrency,amountCur,true);

  
info(strFmt(“%1”, amountMST))


}



Convert Transaction currency to company ledger currency.
The method will convert the transaction currency into accounting currency defined in the ledger.

static void Main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘EUR’;
    AmountCur amountCur = 5500.00;
    AmountMst amountMST;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
    amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
    info(strFmt(‘%1’,amountMST));
}





Convert Company currency to transaction currency.

The method calculates the transaction currency amount from an accounting currency given.

static void  main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘AED’;
    AmountCur amountCur;
    AmountMst amountMST = 5500.00;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea("DUM").RecId), systemDateGet());
    amountCur = currencyExchangeHelper.calculateAccountingToTransaction(transCurrency, amountMST ,true);
    info(strFmt(‘%1’,amountcur));
}

Ledger Dimension D365FO



Ledger Dimension AX2012 & D365FO



In AX -2012 We use DimensionStorage class and method getDynamicAccount to get the Ledger dimension of the following accounts.

For Instance 
DimensionStorage::getDynamicAccount("ABC",LedgerJournalACType::Ledger);
  1. Ledger
  2. Cust
  3. Vend
  4. Project
  5. FixedAssets
  6. Bank
In D365FO  DimensionStorage is removed and the new class introduces LedgerDynamicAccountHelper to get the Ledger dimension of the following accounts.

For Instance 


LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber("Project-001",LedgerJournalACType::Project);


WBS key for a project activity X++ code



WBS key for a project activity X++ code 



Using following SQL Query you can retrieve all activities of one project.

select PURPOSE,ACTIVITYNUMBER from smmActivities
where ACTIVITYNUMBER in (
select ActivityNumber from SmmActivityParentLinkTable
join projTable
            on  projTable.Recid=SmmActivityParentLinkTable.refRecId
   and  SmmActivityParentLinkTable.parentType=7


   where projTable.ProjId='PROJ-0000003')



Using following AX Query you can retrieve all activities of one project.

    SmmActivityParentLinkTable  activityParentLinkTable;
        ProjTable                   projTable;
        ProjectActivityNumber           projectActivityNumber;
        smmActivities               smmActivities;
         
            
            
            
         while   select PURPOSE,ACTIVITYNUMBER from smmActivities
           exists join activityParentLinkTable
            where activityParentLinkTable.ActivityNumber==smmActivities.ActivityNumber
           exists join projTable
            where projTable.Recid==activityParentLinkTable.refRecId
            && activityParentLinkTable.parentType==smmActivityParentType::Project
            && projTable.ProjId=="PROJ-0000003"
        {
         //   projectActivityNumber=new ProjectActivityNumber();

           // projectActivityNumber.ActivityNumber=activityParentLinkTable.ActivityNumber;
           info(strFmt("%1 %2",smmActivities.Purpose, smmActivities.ActivityNumber));
     //       _objContract.addProjectActivity(projectActivityNumber);
        }

Compare Records D365FO & AX 2012





How to compare two records buffer field to field. 



public static container compareRecords(Common _record1, Common _record2)
{
    SysDictTable    dictTable = new SysDictTable(_record1.TableId);
    SysDictField    dictField;
    FieldId         fieldId, extFieldId;
    container       ret;
    int             i, j;
    ;

    if (_record1.TableId != _record2.TableId)
        return conNull();

    for (i=1; i<=dictTable.fieldCnt(); ++i)
    {
        fieldId = dictTable.fieldCnt2Id(i);
        dictField = new SysDictField(_record1.tableId, fieldId);

        if (!dictField.isSystem())
        {
            for (j=1; j<= dictField.arraySize(); ++j)
            {
                extFieldId = fieldId2Ext(fieldId, j);

                if (_record1.(extFieldId) != _record2.(extFieldId))
                {
                    ret += [extFieldId, _record1.(extFieldId), _record2.(extFieldId)];
                }
            }
        }
    }

    return ret;
}




For Demo purpose you can use below code in job/runnable class.


static void demoCompareRecords(Args _args)
{
    VendTable vendTable_1 = VendTable::find('ABC'); 
    VendTable vendTable_2 = VendTable::find('XYZ'); 
 
    container   con;
    int         i;
    ;
 
    con = MyClass::compareRecords(vendTable_1 , vendTable_2 );
 
    for (i=1; i<=conLen(con); i+=3)
    {
        info(strFmt("%1, %2 ,%3"
                   ,fieldId2Name(tableNum(VendTable), conPeek(con, i))
                   ,conPeek(con, i+1)
                   ,conPeek(con, i+2)
                   )
             );
    }
}







Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...