Thursday, 14 April 2016

Email validation in Microsoft Dynamics AX 2012


The below code is used to validate the Email Id.

public boolean validateField(FieldId _fieldIdToCheck)
{
    boolean   ret;
    Str           emailPattern = @"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b";
   
    System.Text.RegularExpressions.Match  myMatch;

    ret = super(_fieldIdToCheck);

    if (_fieldIdToCheck == fieldNum(PracticeDemo, EmailID))
    {
        myMatch = System.Text.RegularExpressions.Regex::Match(this.EmailID, emailPattern);

    if (!myMatch.get_Success())
{
            ret = checkFailed(strFmt("%1 is not an valid email id ", this.EmailID));
}
    }

    return ret;
}

Saturday, 21 November 2015

Department name using default dimension value in AX 2012

We can get the department name in different ways using default dimension value.


1st Way: Using Views.


static void DepartmentName(Args _args)
{
    DefaultDimensionView        defaultDimensionView;
    DimAttributeOMDepartment    dimAttributeOMDepartment;

   //DefaultDimension  =  5637151660
    select DisplayValue from defaultDimensionView
        where defaultDimensionView.DefaultDimension == 5637151660
            && defaultDimensionView.name == 'Department'
        join dimAttributeOMDepartment
            where dimAttributeOMDepartment.Value == defaultDimensionView.DisplayValue;

    info(dimAttributeOMDepartment.Name);
}


2nd Way: Using Tables.


static void getDepartmentName(Args _args)
{
str                                                       name;
DimensionAttributeValueSetItem      valueSetItem; 
DimensionAttribute                           dimAttribute; 
DimensionAttributeValue                 dimAttributeValue;

//Get the Department name for '5637151660' default dimension.
select DimensionAttributeValueSet from valueSetItem 
where valueSetItem.DimensionAttributeValueSet == 5637151660
            join RecId from dimAttributeValue 
                where valueSetItem.DimensionAttributeValue == dimAttributeValue.RecId 
            join RecId from dimAttribute 
                where dimAttributeValue.DimensionAttribute == dimAttribute.RecId 
                   && dimAttribute.Name == enum2str(sysdimension::Department);
       
         name = DimensionAttributeValue::find(dimAttributeValue.RecId).getName();
        
        info(name);
 }




Thursday, 12 March 2015

Adding Customer Address through x++ Coding



The Below code used to update or create address for an existing customer


static void BRR_Address(Args _args)
{
        CustTable                                  custTable;
        DirParty                                     DirParty;
        LogisticsPostalAddress             address;
        DirPartyPostalAddressView      addressView;
        LogisticsLocationRole               roles;


        custtable = Custtable::find("1304");

        address.Street     =   "DLF,";
        address.ZipCode    =   "500006";
        address.City       =   "CyberCity,";
        address.State      =   "TG";
        address.CountryRegionId = "IND";

        addressView.Party = custtable.Party;
        addressview.initFromPostalAddress(address);

        DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
        roles = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery);
        DirParty.createOrUpdatePostalAddress(addressView);
}

Wednesday, 11 March 2015

Inserting Customer's Financial Dimensions through X++ code


The Below code is used for Inserting Financial Dimensions for a particular Customer through code.

static void BRR_Finance(Args _args)
{
  CustTable custTable;
  Struct struct = new Struct();
  container ledgerDimension;
  DimensionDefault DimensionDefault;
  ;
  //set the values
  struct.add("CostCenter", "OU_4740");
  struct.add("BusinessUnit","00000005");
  struct.add("Department","OU_4771");  
  struct.add("ExpensePurpose","Training");
  ledgerDimension += struct.fields();
  ledgerDimension += struct.fieldName(1);
  ledgerDimension += struct.valueIndex(1);
  ledgerDimension += struct.fieldName(2);
  ledgerDimension += struct.valueIndex(2);
  ledgerDimension += struct.fieldName(3);
  ledgerDimension += struct.valueIndex(3);
  ledgerDimension += struct.fieldName(4);
  ledgerDimension += struct.valueIndex(4);
   ttsBegin;
  DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
    //Select the Customer
  custTable = CustTable::find("2003",true);
  custTable.DefaultDimension = DimensionDefault;
  custTable.update();
  ttsCommit;
}

Saturday, 7 March 2015

Finding Ledger Dimension by using MainAccount Number in X++



static void getLedgerDimension(Args _args)
{
DimensionAttributeValueCombination     dimensionAttributeValueCombination;
MainAccount                                             mainAccount;
;
select RecId,MainAccount from dimensionAttributeValueCombination
                join RecId from mainAccount
                  where dimensionAttributeValueCombination.DisplayValue == "1010"
                     && mainAccount.RecId == dimensionAttributeValueCombination.MainAccount;

info(strFmt("Ledger Dimension - %1",dimensionAttributeValueCombination.RecId));
}


                                                or 

we can find by using the method "getDefaultAccountForMainAccountNum()" which is available in DimensionStorage


static void getLedgerDimension(Args _args)
{
   DimensionStorage::getDefaultAccountForMainAccountNum("1010");
}

Tuesday, 24 February 2015

How to open web site pages on AX Forms

Today I will demonstrate you that how you can show any webpage on your AX Forms.

1. Create New Form.
2. Right click the Design node of form and add ActiveX control.
3. Select Microsoft Web Browser from AciveX control window list.
4. Go to method node of form and override Init method of form.
5. Add below line of code
           
    ActiveX.Navigate("www.google.com");

Note: - ActiveX is the name of control which we have added in the form previously.


6. Now run your form and check the output

Saturday, 21 February 2015

Finding the mandatory fields on table by using X++ code.


The below code is used to get the mandatory fields on table using X++.


static void CheckMandatoryFieldsOnTable(Args _args)
{
    DictTable   dictTable;
    DictField    dictField;
    int               i;
   //Pass the table name
    TableId       tableId = tablenum(SalesTable);
    ;

    dictTable = new DictTable(tableId);
    for (i=1 ; i<=dictTable.fieldCnt() ; i++)
    {
        dictField = new DictField(tableId, dictTable.fieldCnt2Id(i));

        if (dictField.mandatory())
        {
            info(dictField.name());
        }

    }
}


output :