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