Wednesday, November 29, 2017

TFS build with DAX Online VSTS

TFS build with DAX

Prerequisite:
Visual studio 2010 with SP1
Team explorer 2010

Steps:
1) Install Visual Studio 2010 with SP1
2) Install Team Explorer 2010
3) Create your team site for TFS Online (https://www.visualstudio.com/team-services/)
4) Configure version control in AX
   4.1) Open Devleopment workspace
   4.2) Version control-> Version control parameter form
   4.3) Create new repository folder in your local drive and mention the path in version control parameter form,
   4.4) Mention the TSF URL of your site
   4.5) Mention name of the project you have created in your TFS site
   4.7) You have to create one root folder under the repository folder
       and mention the name of that folder in “Application rood folder” text box in parameter form
   4.8) enter login credential for your TFS site
5) Configured TFS site and AX

Download Auto Build script
Auto Build Script

AX Build Tool
AX build Tool

Combine XPO tool
Code in CMD prompt
CombineXPOs.exe -XpoDir D:\XPO\Project1.xpo D:\XPO\Project2.xpo

Thursday, November 23, 2017

RLS & XDS in DAX


Difference Between RLS & XDS

Record Level Security(RLS):
RLS was only a filter on forms. When you have two or more roles with the same table you need to apply id on all roles. When you access the table from outside AX (e.g. business connector), there was no filter applied.
Extensible Data Security(XDS): XDS adds statements to queries on AOS level. So the data will be filtered if you have defined multiple roles where only one role has an XDS policy.

XDS reference steps link: https://www.dynamics101.com/implementing-role-based-extensible-data-security-xds-policies-in-microsoft-dynamics-ax-2012/


XDS:

XDSServices  xdsServices = new XDSServices();
str getSQLxds;
;
xdsServices.setXDSState(0); //Disable XDS

xdsServices.setXDSState(1); //Enable XDS

//To Get XDS policy name(Restricted data) and defined Query from Table name as input)

getSQLxds = xdsService.getTableSQL("TableNum");
info(getSQLxds);

Tuesday, November 14, 2017

Execute Store Procedure in X++

Connection connection = new Connection();
Statement statement = connection.createStatement();
str sqlCode = 'EXECUTE  ';// Store procedure statement in X++
SqlStatementExecutePermission permission = new SqlStatementExecutePermission(sqlCode);
permission.assert();
statement.executeQuery(sqlCode);

Tuesday, November 7, 2017

Method and its associated ( Preceding & Succeeding event) in DAX 365


Reference Source Link: https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/extensibility/customization-overlayering-extensions

Published form DataSource method
Preceding eventSucceeding event
activeN/AActivated
deleteDeletingDeleted
validateWriteValidatingWritingValidatedWrite
writeWritingWritten
createCreatingCreated
executeQueryN/AQueryExecuted
linkActiveN/APostLinkActive
initN/AInitialized
validateDeleteValidatingDeleteValidatedDelete
rereadN/AReread
selectionChangedN/ASelectionChanged
markChangedN/AMarkChanged
leaveRecordLeavingRecordLeftRecord
Published form Object methodPreceding eventSucceeding event
initInitializingInitialized
closeClosingN/A
runN/APostRun
activateN/AActivated
Published form Control methodPreceding eventSucceeding event
modifiedN/AModified
validateValidatingValidated
leaveLeavingLostFocus
enterN/AEnter
gotFocusN/AGotFocus
clickedN/AClicked
selectionChangeSelectionChangingN/A
pageActivatedN/APageActivated
allowPageDeactivateAllowPageDeactivateN/A
expandExpandingExpanded
tabChangedN/ATabChanged
dialogClosedN/ADialogClosed


Published Table methodPreceding eventSucceeding event
validateWriteValidatingWriteValidatedWrite
validateDeleteValidatingDeleteValidatedDelete
validateFieldValidatingFieldValidatedField
validateFieldValueValidatingFieldValueValidatedFieldValue
modifiedFieldModifyingFieldModifiedField
modifiedFieldValueModifyingFieldValueModifiedFieldValue
InsertInsertingInserted
UpdateUpdatingUpdated
DeleteDeletingDeleted
InitvalueInitializingRecordInitializedRecord
FinalDeleteValidationExecuted when a delete operation is performed on a table object, before the operation is committed to the underlying database tableN/A
FinalInsertValidationExecuted when an insert operation is performed on a table object, before the operation is committed to the underlying database tableN/A
FinalReadValidationExecuted when a read operation is performed on a table object.N/A
FinalUpdateValidationExecuted when an update operation is performed on a table object, before the operation is committed to the underlying database table.N/A

Tuesday, October 31, 2017

Process AIF in Ax 2012

static void San_ProcessAIF(Args _args)
{
    new AifGatewayReceiveService().run();
    new AifInboundProcessingService().run();
    new AifOutboundProcessingService().run();
    new AifGatewaySendService().run();
}

Project Quotation Sent/Confirm & transfer in AX 2012 (X++)

//Sales Project Quotation Sent/Confirm & transfer in X++

static void SalesProjQuotation(Args _args)
{
    SalesQuotationLine              salesQuotationLine;
    CustQuotationJour               custQuotationJour;
    CustQuotationTrans              locCustQuotationTrans;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationProjLinkWizard    salesQuotationProjLinkWizard;
    ProjTable                       projTable;
    CustQuotationConfirmJour        custQuotationConfirmJour;
    SalesQuotationTransferToProject salesQuotationTransferToProject;

    #AviFiles
    SysOperationProgress progress = new SysOperationProgress();
    int i;
 //Function to send Project Quotation
void salesProjectQuotationSent(Common _record, DocumentStatus _documentStatus, QuotationDocNum  _quotationDocNum = '')
{
    #define.project('Project')
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationParmTable         salesQuotationParmTable;
    SalesQuotationEditLinesForm     salesQuotationEditLinesForm = SalesQuotationEditLinesForm::construct(_documentStatus, #project, true);
    ParmId                          parmId = salesQuotationEditLinesForm.parmId();

    if (_record)
    {
        if (_record.TableId == tableNum(SalesQuotationTable))
        {
            salesQuotationTable = _record;
            salesQuotationEditLinesForm.initParmSalesQuotationTable(salesQuotationTable);
        }
        salesQuotationEditLinesForm.createParmUpdate();
        salesQuotationEditLinesForm.createParmTable(salesQuotationParmTable, salesQuotationTable);
        salesQuotationParmTable.insert();

        salesQuotationEditLinesForm.callerModuleAxapta(SalesQuotationEditLinesForm::getCallerModuleFromParm(#project));
        salesQuotationEditLinesForm.parmId(parmId);
        salesQuotationEditLinesForm.parmTransDate(systemDateGet());
        salesQuotationEditLinesForm.prePromptInit();
        salesQuotationEditLinesForm.run();
    }
}

    ;
    // Approve Sales Quotations
    ttsBegin;
    update_recordSet salesQuotationTable
        setting QuotationStatus = SalesQuotationStatus::Approved
        where salesQuotationTable.QuotationStatus == SalesQuotationStatus::Created;
    ttsCommit;

    info("Updated to Approved successfully.");

    // Send the Quotation
    ttsBegin;
    while select forUpdate salesQuotationTable
        where salesQuotationTable.QuotationStatus == SalesQuotationStatus::Approved
    {
        salesProjectQuotationSent(salesQuotationTable, DocumentStatus::Quotation);
    }
    ttsCommit;

    info("Updated to Sent successfully.");


    // Confirm and Transfering to Project
    salesQuotationTransferToProject = new SalesQuotationTransferToProject();
    salesQuotationProjLinkWizard =  new SalesQuotationProjLinkWizard ();

    progress = SysOperationProgress::newGeneral(#aviUpdate, 'Confirming Sales Project Quotation.', 1000);

    while select salesQuotationTable
        where salesQuotationTable.QuotationStatus == SalesQuotationStatus::Sent
    {
        infolog.clear();
        projTable.clear();
        salesQuotationLine.clear();
        custQuotationJour.clear();
        custQuotationConfirmJour.clear();

        projTable = ProjTable::find(salesQuotationTable.ProjIdRef, true);

        select firstOnly forUpdate custQuotationJour
                where custQuotationJour.ProjIdRef       == salesQuotationTable.ProjIdRef;

        if(projTable.status().validateConfirmAndTransfer())
        {           
            salesQuotationProjLinkWizard.parmProjTable(projTable);
            salesQuotationProjLinkWizard.parmSalesQuotationTable(salesQuotationTable);
            salesQuotationProjLinkWizard.linkQuotationToProject(projTable.ProjId, projTable.ProjInvoiceProjId);
            salesQuotationProjLinkWizard.linkConfirmationToProject(projTable.ProjId, projTable.ProjInvoiceProjId);

            ttsBegin;
            // update the Sales project Quotation
            salesQuotationProjLinkWizard.parmModelId(ProjParameters::find().ModelId);
            salesQuotationProjLinkWizard.transferForecastToProject();
            salesQuotationProjLinkWizard.transferItemReq();
            salesQuotationProjLinkWizard.updateTransferredToProject(true, true);
            ttsCommit;
        }

        i++;
        progress.incCount();
        progress.setText(strfmt("Sales Project Quotation confirmed: %1", i));
        sleep(100);
    }
}

Posting Project BegBalance in AX 2012

    ProjJournalTable            projJournalTable;
    ProjBegBalJournalCheckPost  projBegBalJournalCheckPost;
    LedgerVoucher               ledgerVoucher;
    JournalTableData            journalTableData;
    ;

    try
    {
        ttsBegin;

        while select forUpdate projJournalTable
                         where projJournalTable.Posted      == NoYes::No &&
                               projJournalTable.JournalType == ProjJournalType::BegBalance
        {
            projBegBalJournalCheckPost = null;
            projBegBalJournalCheckPost = ProjBegBalJournalCheckPost::newJournalCheckPost(false,
                                                            false,
                                                            JournalCheckPostType::Post,
                                                            projJournalTable.TableId,
                                                            projJournalTable.JournalId);

            journalTableData = JournalTableData::newTable(projJournalTable);

            projBegBalJournalCheckPost.postTransLedger(journalTableData.journalTransList().journalTransData(), ledgerVoucher);

        }

        ttsCommit;

        info("Posted successfully.");
    }
    catch
    {
        info("Posting failed.");
    }
}

Get Organisation hierarchies through X++/SQL

In AX 2012

//Project XPO Download link

Organisation Hierarchies

XPO Project Contains,

1) Query - OrganisationHierarchies
2) View - OrganisationHierarchies
3) Job - GetOrgansationalHierarchy

static void  GetOrgansationalHierarchy(Args _args)
{
    //Reference Query : OMHierarchy
    OMHierarchyType OMHierarchyType1;
    OMHierarchyRelationship OMHierarchyRelationship1;
    OMRevisionEdit OMRevisionEdit1; //check this too
    OMInternalOrganization  omInternalOrganizationP,omInternalOrganizationC;
    OMOperatingUnit  omOperatingUntInt;
 
    //Function to Clear
    void clearBuffer()
    {
        OMHierarchyType1.clear();
        omInternalOrganizationP.clear();
        omInternalOrganizationC.clear();
        omOperatingUntInt.clear();
        OMRevisionEdit1.clear();
        OMHierarchyRelationship1.clear();
    }
    ;
    clearBuffer();
    while select Name,RecId
                from OMHierarchyType1
    {
        while select HierarchyType,ParentOrganization,ChildOrganization
                from  OMHierarchyRelationship1
            where OMHierarchyRelationship1.HierarchyType == OMHierarchyType1.RecId
                    && OMHierarchyRelationship1.ParentOrganization != 0
               outer join  omInternalOrganizationP //Parent Organization
                     where omInternalOrganizationP.RecId == OMHierarchyRelationship1.ParentOrganization
                outer join omInternalOrganizationC //Child Organization
                    where omInternalOrganizationC.RecId == OMHierarchyRelationship1.ChildOrganization
                outer join omOperatingUntInt // Operating unit Type
                    where omOperatingUntInt.PartyNumber == omInternalOrganizationC.PartyNumber
                 
        {
            info(strFmt("Org,%1,%2,%3,%4",OMHierarchyType1.Name,
                                   omInternalOrganizationP.Name,
                                   omInternalOrganizationC.Name,
                                   omOperatingUntInt.OMOperatingUnitType
                                   ));
        }
    }
}


In SQL

SQL Script Query

CREATE VIEW vORGANISATIONHIERARCHIES
AS
SELECT
T1.NAME AS HIERARCHYNAME,
T2.CHILDORGANIZATION AS CHILDORGANIZATION,
T2.PARENTORGANIZATION AS PARENTORGANIZATION,
T2.HIERARCHYTYPE AS HIERARCHYTYPE,
T3.NAME AS PARENT,
T4.NAME AS CHILD,
T5.OMOPERATINGUNITTYPE AS ChildOMOPERATINGUNITTYPE,
T5.OMOPERATINGUNITNUMBER AS ChildOMOPERATINGUNITNUMBER,
T6.OMOPERATINGUNITNUMBER AS ParentOMOPERATINGUNITNUMBER,
T6.OMOPERATINGUNITTYPE AS ParentOMOPERATINGUNITTYPE
FROM OMHIERARCHYTYPE T1
CROSS JOIN OMHIERARCHYRELATIONSHIP T2
LEFT OUTER JOIN DIRPARTYTABLE T3
ON (T2.PARENTORGANIZATION=T3.RECID)
LEFT OUTER JOIN DIRPARTYTABLE T4
ON (T2.CHILDORGANIZATION=T4.RECID)
LEFT OUTER JOIN DIRPARTYTABLE T5
ON ((T4.RECID=T5.RECID)
AND (T5.INSTANCERELATIONTYPE IN (2377) ))
LEFT OUTER JOIN DIRPARTYTABLE T6
ON ((T3.RECID=T6.RECID)
AND (T6.INSTANCERELATIONTYPE IN (2377) ))
 WHERE ( NOT ((T2.PARENTORGANIZATION=0))
AND (T1.RECID=T2.HIERARCHYTYPE))

Thursday, October 26, 2017

Import Currency Exchange Rates in Dynamics AX


\\Input
Parm Class

CurrencyCode                fromCurrencyCode;
CurrencyCode                toCurrencyCode;
TransDate                   exchangeRateDate;
CurrencyExchangeRate        exchangeRate;
ExchangeRateTypeRecId       exchangeRateTypeRecId;
ExchangeRateDisplayFactor   exchangeRateDisplayFactor;

fromCurrencyCode = CompanyInfo::standardCurrency();
exchangeRateType            = "Default";
exchangeRateTypeRecId = ExchangeRateType::find(exchangeRateType).RecId;
updateExchangeRates         = Noyes::yes;
exchangeRateDisplayFactor   = ExchangeRateDisplayFactor::One;

Table: ExchangeRate
Table Method
/// <summary>
/// Imports an exchange rate between the from currency and the accounting currency for the default
/// exchange rate type.
/// </summary>
/// <param name="_fromCurrencyCode">
/// The from currency.
/// </param>
/// <param name="_toCurrencyCode">
/// The to currency.
/// </param>
/// <param name="_exchangeRateTypeRecId">
/// The exchange rate type ID.
/// </param>
/// <param name="_exchangeRateDate">
/// The exchange rate date.
/// </param>
/// <param name="_exchangeRate">
/// The exchange rate.
/// </param>
/// <param name="_insertExchangeRate">
/// A Boolean value that determines whether to insert exchange rates.
/// </param>
/// <param name="_updateExchangeRate">
/// A Boolean value that determines whether to update exchange rates.
/// </param>
/// /// <param name="_exchangeRateDisplayFactor">
/// An exchange rate display factor
/// </param>
public static void importExchangeRate(
    CurrencyCode _fromCurrencyCode,
    CurrencyCode _toCurrencyCode,
    ExchangeRateTypeRecId _exchangeRateTypeRecId,
    TransDate _exchangeRateDate,
    CurrencyExchangeRate _exchangeRate,
    boolean _insertExchangeRate,
    boolean _updateExchangeRate,
    ExchangeRateDisplayFactor _exchangeRateDisplayFactor = 0)
{
    ExchangeRateCurrencyPair exchangeRateCurrencyPair;
    ExchangeRate exchangeRate;
    ;
    date exchangeRateDate = _exchangeRateDate;
    ttsbegin;
    if (_insertExchangeRate || _updateExchangeRate)
    {
        select RecId from exchangeRateCurrencyPair
            where exchangeRateCurrencyPair.FromCurrencyCode == _fromCurrencyCode
                && exchangeRateCurrencyPair.ToCurrencyCode == _toCurrencyCode
                && exchangeRateCurrencyPair.ExchangeRateType == _exchangeRateTypeRecId;
        if (exchangeRateCurrencyPair)
        {
            select firstonly forupdate validtimestate(exchangeRateDate) ExchangeRate from exchangeRate
                where exchangeRate.ExchangeRateCurrencyPair == exchangeRateCurrencyPair.RecId
                    && exchangeRate.ValidFrom == exchangeRateDate;
        }
        if (exchangeRate)
        {
            if (_updateExchangeRate)
            {
                exchangeRate.ExchangeRate = _exchangeRate;
                exchangeRate.update();
            }
        }
        else
        {
            if (_insertExchangeRate)
            {
                if (!exchangeRateCurrencyPair)
                {
                    exchangeRateCurrencyPair.FromCurrencyCode = _fromCurrencyCode;
                    exchangeRateCurrencyPair.ToCurrencyCode = _toCurrencyCode;
                    exchangeRateCurrencyPair.ExchangeRateType = _exchangeRateTypeRecId;
                 
                    if (_exchangeRateDisplayFactor)
                    {
                        exchangeRateCurrencyPair.ExchangeRateDisplayFactor = _exchangeRateDisplayFactor;
                    }
                 
                    exchangeRateCurrencyPair.insert();
                }
                exchangeRate.clear();
                exchangeRate.ExchangeRateCurrencyPair = exchangeRateCurrencyPair.RecId;
                exchangeRate.ExchangeRate = _exchangeRate;
                exchangeRate.ValidFrom = _exchangeRateDate;             
                if (_exchangeRateDisplayFactor)
                {
                    exchangeRateCurrencyPair.ExchangeRateDisplayFactor = _exchangeRateDisplayFactor;
                }             
                exchangeRate.insert();
            }
        }
    }
    ttscommit;
}

Wednesday, October 25, 2017

Multiselect lookup in form Datasource fields in AX 2012

// Multi select lookup in form Data source fields in AX 2012

Note: This will not work for Dynamic string control in FORM


Class declaration
SysLookupMultiSelectCtrl    msCtrl;

Init
SysLookupMultiSelectCtrl::construct(element, <control name>, querystr(<queryName>));

Properties
string control auto declaration property set to Yes

SysLookupMultiSelectCtrl class
Method -> Init
//Function
boolean isOnGrid(FormStringControl _ctrl)
    {
        FormControl     parentControl;
        FormControl     currentControl;
        boolean         retValue;
        currentControl  = _ctrl;
        retValue        = false;
        while(currentControl.parentControl() && !retValue)
        {
            parentControl = currentControl.parentControl();
            if(parentControl is FormGridControl)
                retValue = true;
            else
                currentControl = currentControl.parentControl();
        }
        return retValue;
    }
;
     if(isOnGrid(fsCtrlNames))
    {
        fsCtrlNames.registerOverrideMethod('modified', 'ctrlNames_textChange', this);
    }
    else
    {
        fsCtrlNames.registerOverrideMethod('textChange', 'ctrlNames_textChange', this);
    }

Method -> ctrlNames_textChange
 FormDataSource      fds;
    Common              anyBuffer;
    _fsCtrlNames.text(fsCtrlNamesTmp.text());
    fds = _fsCtrlNames.dataSourceObject();
    if(fds)
    {
        anyBuffer = fds.cursor();
        anyBuffer.(_fsCtrlNames.dataField()) = fsCtrlNamesTmp.text();
        fds.refresh();
    }
    fsCtrlNames.modified();


Other Reference: https://krishhdax.blogspot.in/2015/06/editable-multi-select-lookup-in-grid.html

Inventory visibility in D365FO

 Inventory visibility 1. InventInventoryDataServiceBatchJobTask => Method (create) 2. InventSum => InventInventoryDataServiceInventSum...