Create Vendor using X++ D365FO & AX-2012


Create Vendor using X++ D365FO & AX-2012



Following Code will help you to create Vendor using X++

For Default Dimension please check Link

public class VendorHelper
{

 

   

  
        private void new()
        {
        }

        public static VendorHelper construct()
        {
            return new VendorHelper();
        }

        public void createVendor()
        {
            VendTable                    vendTable;
            NumberSeq                    numberSeq;
            Name                         name ='Systems Limited Karachi, Pakistan';

            DirParty                        dirParty;
            DirPartyPostalAddressView       dirPartyPostalAddressView;
            DirPartyContactInfoView         dirPartyContactInfo;
            ;
            container      conAttribute=["BusinessUnit","CostCenter","Department"];
            container      conAttributeValue=["001","007","022"];
            /* Marks the beginning of a transaction.
            Necessary to utilize the method numRefCustAccount() */
            ttsBegin;
            vendTable.initValue();

            try
{
                //vendTable
            //numberSeq               = NumberSeq::newGetNum(VendParameters::numRefVendAccount())
                // vendTable.AccountNum    = numberSeq.num();
                vendTable.AccountNum    = "Vend-00099";
                vendTable.VendGroup     ='30';
                vendTable.Currency      ='USD';
                vendTable.PaymTermId    ='Net10';
                vendTable.PaymMode      ='CHECK';
                vendTable.DefaultDimension=DefaultDimesnionHelper::createDefaultDimension(conAttribute,conAttributeValue);
                vendTable.insert();

                //DirParty

                /* Creates a new instance of the DirParty class from an address book entity
                that is represented by the custTable parameter. */
                dirParty = DirParty::constructFromCommon(vendTable);

                dirPartyPostalAddressView.LocationName      ='Systems limited Karachi, Pakistan ';
                dirPartyPostalAddressView.City              ='Karachi';
                dirPartyPostalAddressView.Street            ='Shah-re-faisal alcope-house';
                dirPartyPostalAddressView.StreetNumber      ='18';
                dirPartyPostalAddressView.CountryRegionId   ='PAK';
                dirPartyPostalAddressView.State             ='Sindh';
                dirPartyPostalAddressView.IsPrimary             = NoYes::Yes;
                // Fill address
                dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);


                dirPartyContactInfo.LocationName    ='Email Address';
                dirPartyContactInfo.Locator         ='ShaikhSohailHussain@gmail.com';
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;

                // Fill Contacts
                dirParty.createOrUpdateContactInfo(dirPartyContactInfo);


                dirPartyContactInfo.LocationName    ='Mobile Number';
                dirPartyContactInfo.Locator         ='923422722538';
                dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
                dirPartyContactInfo.IsPrimary       = NoYes::Yes;

                // Fill Contacts
                dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

                // Marks the end of transaction.
                ttsCommit;
            }
            catch(Exception::Error)
            {
                ttsAbort;
                throw Exception::Error;
            }
        }

}

Support Faryal's Cusine


Default Dimension D365FO AX-2012


Default Dimension D365FO AX-2012





Following Code will help you to create Default Dimension using X++



Default Dimension Class 


public class DefaultDimesnionHelper
{

    public static DimensionDefault createDefaultDimension(container conAttribute,container attributeValue)
    {
        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault                    result;
  
        int                     i;
        DimensionAttribute      dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
  
        // Note that "Item" is not one of the default dimension,
        // but DimensionAttributeValueSetStorage will handle it gracefully
        container               conAttr = conAttribute;
        container               conValue = attributeValue;
        str                     dimValue;
  
        for (i = 1; i <= conLen(conAttr); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
      
            if (dimensionAttribute.RecId == 0)
            {
                continue;
            }
      
            dimValue = conPeek(conValue,i);
      
            if (dimValue != "")
            {
                // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
                dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
          
                // Add the dimensionAttibuteValue to the default dimension
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
  
        result = valueSetStorage.save();
        return result;
    }


}

Support Faryal's Cusine


Create Customer using X++ D365FO & AX-2012




Create Customer using X++ D365FO & AX-2012



Following Code will help you to create customer using X++



Default Dimension Class 


public class DefaultDimesnionHelper
{

    public static DimensionDefault createDefaultDimension(container conAttribute,container attributeValue)
    {
        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault                    result;
  
        int                     i;
        DimensionAttribute      dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
  
        // Note that "Item" is not one of the default dimension,
        // but DimensionAttributeValueSetStorage will handle it gracefully
        container               conAttr = conAttribute;
        container               conValue = attributeValue;
        str                     dimValue;
  
        for (i = 1; i <= conLen(conAttr); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
      
            if (dimensionAttribute.RecId == 0)
            {
                continue;
            }
      
            dimValue = conPeek(conValue,i);
      
            if (dimValue != "")
            {
                // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
                dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
          
                // Add the dimensionAttibuteValue to the default dimension
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
  
        result = valueSetStorage.save();
        return result;
    }


}




Customer Code



public class CustomerHelper
{


   

    private void new()
    {
    }

    public static CustomerHelper construct()
    {
        return new CustomerHelper();
    }

    public void createCustomer()
    {
        CustTable                    custTable;
        NumberSeq                    numberSeq;
        Name                         name ='Systems Limited Karachi, Pakistan';

        DirParty                        dirParty;
        DirPartyPostalAddressView       dirPartyPostalAddressView;
        DirPartyContactInfoView         dirPartyContactInfo;
        ;
        container      conAttribute=["BusinessUnit","CostCenter","Department"];
        container      conAttributeValue=["001","007","022"];
        /* Marks the beginning of a transaction.
        Necessary to utilize the method numRefCustAccount() */
        ttsBegin;
        custTable.initValue();

        try
        {
            //CustTable
            //numberSeq               = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
            // custTable.AccountNum    = numberSeq.num();
            custTable.AccountNum    = "US-00099";
            custTable.CustGroup     ='30';
            custTable.Currency      ='USD';
            custTable.PaymTermId    ='Net10';
            custTable.PaymMode      ='CHECK';
            custTable.DefaultDimension=DefaultDimesnionHelper::createDefaultDimension(conAttribute,conAttributeValue);
            custTable.insert(DirPartyType::Organization, name);

            //DirParty

            /* Creates a new instance of the DirParty class from an address book entity
            that is represented by the custTable parameter. */
            dirParty = DirParty::constructFromCommon(custTable);

            dirPartyPostalAddressView.LocationName      ='Systems limited Karachi, Pakistan ';
            dirPartyPostalAddressView.City              ='Karachi';
            dirPartyPostalAddressView.Street            ='Shah-re-faisal alcope-house';
            dirPartyPostalAddressView.StreetNumber      ='18';
            dirPartyPostalAddressView.CountryRegionId   ='PAK';
            dirPartyPostalAddressView.State             ='Sindh';
            dirPartyPostalAddressView.IsPrimary             = NoYes::Yes;
            // Fill address
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);


            dirPartyContactInfo.LocationName    ='Email Address';
            dirPartyContactInfo.Locator         ='ShaikhSohailHussain@gmail.com';
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;

            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);


            dirPartyContactInfo.LocationName    ='Mobile Number';
            dirPartyContactInfo.Locator         ='923422722538';
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;

            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

            // Marks the end of transaction.
            ttsCommit;
        }
        catch(Exception::Error)
        {
            ttsAbort;
            throw Exception::Error;
        }
    }


}

Kindly check the below screenshot







Support Faryal's Cusine


Import Export Model D365FO



Import Export Model D365FO





Export Model

ModelUtil.exe -export -metadatastorepath=[path of the metadata store] -modelname=[name of the model to export] -outputpath=[path of the folder where the model file should be saved]

ModelUtil.exe -export -metadatastorepath=C:\AOSService\PackagesLocalDirectory -modelname="FleetManagement" -outputpath=c:\temp



Import Model

ModelUtil.exe -import -metadatastorepath=[path of the metadata store where model should be imported] -file=[full path of the file to import]

ModelUtil.exe -import -metadatastorepath=C:\AOSService\PackagesLocalDirectory -modelname="FleetManagement" -outputpath=c:\temp


Important 
You can find the model name in Descriptor file in the tag of   <DisplayName> Tag



Support Faryal's Cusine


Generate class from SQL database table


Generate class from SQL database table




declare @TableName sysname = 'BANKACCOUNT'
declare @Result varchar(max) = 'public class ' + UPPER(LEFT(@TableName,1))+LOWER(SUBSTRING(@TableName,2,LEN(@TableName)))  + 'Entity

{'

select @Result = @Result + '
    public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
'
from
(
    select
        replace(col.name, ' ', '_') ColumnName,
        column_id ColumnId,
        case typ.name
            when 'bigint' then 'long'
            when 'binary' then 'byte[]'
            when 'bit' then 'bool'
            when 'char' then 'string'
            when 'date' then 'DateTime'
            when 'datetime' then 'DateTime'
            when 'datetime2' then 'DateTime'
            when 'datetimeoffset' then 'DateTimeOffset'
            when 'decimal' then 'decimal'
            when 'float' then 'float'
            when 'image' then 'byte[]'
            when 'int' then 'int'
            when 'money' then 'decimal'
            when 'nchar' then 'char'
            when 'ntext' then 'string'
            when 'numeric' then 'decimal'
            when 'nvarchar' then 'string'
            when 'real' then 'double'
            when 'smalldatetime' then 'DateTime'
            when 'smallint' then 'short'
            when 'smallmoney' then 'decimal'
            when 'text' then 'string'
            when 'time' then 'TimeSpan'
            when 'timestamp' then 'DateTime'
            when 'tinyint' then 'byte'
            when 'uniqueidentifier' then 'Guid'
            when 'varbinary' then 'byte[]'
            when 'varchar' then 'string'
            else 'UNKNOWN_' + typ.name
        end ColumnType,
        case
            when col.is_nullable = 1 and typ.name in ('bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal', 'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint', 'smallmoney', 'time', 'tinyint', 'uniqueidentifier')
            then '?'
            else ''
        end NullableSign
    from sys.columns col
        join sys.types typ on
            col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id
    where object_id = object_id(@TableName)
) t
order by ColumnId

set @Result = @Result  + '
}'

print @Result






public class BankaccountEntity

{
    public int ID { get; set; }

    public string BANK { get; set; }

    public string ROUNTINGNUM { get; set; }

    public string CURRENCY { get; set; }

    public string ACCOUNTNUM { get; set; }

    public int? MAINACCOUNTID { get; set; }

    public string IBAN { get; set; }

    public string SWIFT { get; set; }

    public string BRANCH { get; set; }

    public string CONTACTPERSON { get; set; }

    public string CONTACTPHONE { get; set; }

    public string CONTACTEMAIL { get; set; }

    public bool? STATUS { get; set; }

}


Support Faryal's Cusine


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...