Thursday, December 5, 2013

Code to create masters in AX 2012


Vendor master creation through code in AX 2012

DirPerson           dirPerson;
DirPersonName dirPersonName;
DirParty             dirParty;
VendTable         vendTable;
DirOrganization  dirOrganisation;
;

//If record type is Person

/*dirPerson.Name             = 'Test name';
dirPerson.NameAlias        = 'Test alias name';
dirPerson.NameSequence = dirNameSequence::find('First Last').RecId;
dirPerson.insert();


dirPersonName.FirstName       = 'Test first name';
dirPersonName.MiddleName   = 'Test middle name';
dirPersonName.LastName       = 'Test last name';
dirPersonName.ValidFrom      = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
dirPersonName.ValidTo          = DateTimeUtil::maxValue();
dirPersonName.Person            = dirPerson.RecId;
dirPersonName.insert();


dirParty = new DirParty(dirPerson);*/

//If record type is Organization

dirOrganisation.Name               = 'Test name';
dirOrganisation.NameAlias       = 'Test alias name';
dirOrganisation.LanguageId      = 'EN-US';
dirOrganisation.KnownAs        = 'Test';
dirOrganisation.PhoneticName = 'Test phonetic name';
dirOrganisation.insert();


dirParty = new DirParty(dirOrganisation);


ttsBegin;
vendTable.initValue();
vendTable.AccountNum       = 'VENDTEST_001';
vendTable.Party                   = dirOrganisation.RecId; //dirPerson.RecId;
vendTable.Currency             = 'AED';
vendTable.VendGroup         = '10';
vendTable.initFromVendGroup(VendGroup::find(vendTable.VendGroup));
vendTable.insert();
ttsCommit;



Customer master creation through code in AX 2012


DirPerson            dirPerson;
DirPersonName  dirPersonName;
DirParty              dirParty; 
CustTable           custTable;
DirOrganization   dirOrganisation;
;

//If record type is Person

/*dirPerson.Name              = 'Test name';
dirPerson.NameAlias         = 'Test alias name';
dirPerson.NameSequence  = dirNameSequence::find('First Last').RecId;
dirPerson.insert();


dirPersonName.FirstName         = 'Test first name';
dirPersonName.MiddleName     = 'Test middle name';
dirPersonName.LastName         = 'Test last name';
dirPersonName.ValidFrom        = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
dirPersonName.ValidTo            = DateTimeUtil::maxValue();
dirPersonName.Person              = dirPerson.RecId;
dirPersonName.insert();


dirParty = new DirParty(dirPerson);*/

//If record type is Organization

dirOrganisation.Name              = 'Test name';
dirOrganisation.NameAlias      = 'Test alias name';
dirOrganisation.LanguageId     = 'EN-US';
dirOrganisation.KnownAs       = 'Test';
dirOrganisation.PhoneticName = 'Test phonetic name';
dirOrganisation.insert();

dirParty = new DirParty(dirOrganisation);


ttsBegin;
custTable.clear();
custTable.initValue();
custTable.Party              = dirOrganisation.RecId;
custTable.AccountNum  = 'CUST0001';
custTable.Currency        = 'USD';
custTable.CustGroup     = '20';
custTable.initFromCustGroup(CustGroup::find(custTable.CustGroup));
custTable.insert();
ttsCommit;




Retail store master creation through code in AX 2012

RetailStoreTable    store; 
OMOperatingUnit operatingUnit;
DirOrganization     orgn;
DirParty                dirParty;
NumberSeq           numSeq;


orgn.clear();
orgn.Name          = 'Store1';
orgn.NameAlias  = 'Store1 alias name';
orgn.LanguageId = 'EN-US';
orgn.insert();

dirParty = new DirParty(orgn);

numSeq = NumberSeq::newGetNum(OMOperatingUnit::getNumberSequenceReference());

operatingUnit.initFromDirParty(dirParty);
operatingUnit.Name                                = 'Store1';
operatingUnit.OMOperatingUnitNumber = numSeq.num();
operatingUnit.OMOperatingUnitType      = OMOperatingUnitType::RetailChannel;
operatingUnit.LanguageId                        = 'EN-US';
operatingUnit.insert();

store.initValue();

store.OMOperatingUnitID  = operatingUnit.RecId;
store.DefaultCustAccount   = 'CUST0001'; //default cust account based on the requirement
store.inventLocation            = 'Loc1';
store.StoreNumber             = 'Store1';
store.Currency                    = 'SAR';
store.taxGroup                    = 'TaxGrp1';
store.insert();

No comments:

Post a Comment