Tuesday, April 12, 2016
Importing Vendor Into Ax 2012
static void importVendor(Args _args)
{
CommaIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
Name name,contactName;
VendTable vendtable;
FileName fileName;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
filename = dfFileName.value();
}
csvFile = new CommaIO(filename, 'r');
if (csvFile)
{
readCon = csvFile.read();
ttsbegin;
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if (readCon)
{
name = conPeek(readCon,2);
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
vendtable.clear();
vendtable.initValue();
vendtable.Party = partyRecId;
vendtable.AccountNum = conPeek(readCon,1);
vendtable.VendGroup = conPeek(readCon,5);
vendtable.Currency = conPeek(readCon,6);
//vendtable.Blocked =
vendtable.DlvMode = conPeek(readCon,8);
vendtable.PaymMode = conPeek(readCon,9);
ContactPerson = conPeek(readCon,12);
if(contactperson != '')
{
contactname = conPeek(readCon,12);
ContactPerson::findOrCreateNameParty(partyRecId,contactname);
}
vendtable.insert();
address.CountryRegionId = strLRTrim(conPeek(readCon,14));
//addressView.State = strLRTrim(conPeek(readCon,16));
address.ZipCode = strLRTrim(conPeek(readCon,15));
address.Street = strLRTrim(conPeek(readCon,19));
// address.county = strLRTrim(conPeek(readCon,17));
address.City = strLRTrim(conPeek(readCon,18));
addressView.LocationName = name;
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
contactView.LocationName = "Delivery email";
contactView.Locator = strLRTrim(conPeek(readCon,10));
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Cellular Phone";
contactView.Locator = strLRTrim(conPeek(readCon,11));
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Phone";
contactView.Locator = strLRTrim(conPeek(readCon,3));
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Fax";
contactView.Locator = strLRTrim(conPeek(readCon,4));
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
inserted++;
}
}
ttsCommit;
}
info(strfmt("%1 records inserted out of %2",inserted,icount));
}
{
CommaIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
Name name,contactName;
VendTable vendtable;
FileName fileName;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
filename = dfFileName.value();
}
csvFile = new CommaIO(filename, 'r');
if (csvFile)
{
readCon = csvFile.read();
ttsbegin;
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if (readCon)
{
name = conPeek(readCon,2);
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
vendtable.clear();
vendtable.initValue();
vendtable.Party = partyRecId;
vendtable.AccountNum = conPeek(readCon,1);
vendtable.VendGroup = conPeek(readCon,5);
vendtable.Currency = conPeek(readCon,6);
//vendtable.Blocked =
vendtable.DlvMode = conPeek(readCon,8);
vendtable.PaymMode = conPeek(readCon,9);
ContactPerson = conPeek(readCon,12);
if(contactperson != '')
{
contactname = conPeek(readCon,12);
ContactPerson::findOrCreateNameParty(partyRecId,contactname);
}
vendtable.insert();
address.CountryRegionId = strLRTrim(conPeek(readCon,14));
//addressView.State = strLRTrim(conPeek(readCon,16));
address.ZipCode = strLRTrim(conPeek(readCon,15));
address.Street = strLRTrim(conPeek(readCon,19));
// address.county = strLRTrim(conPeek(readCon,17));
address.City = strLRTrim(conPeek(readCon,18));
addressView.LocationName = name;
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
contactView.LocationName = "Delivery email";
contactView.Locator = strLRTrim(conPeek(readCon,10));
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Cellular Phone";
contactView.Locator = strLRTrim(conPeek(readCon,11));
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Phone";
contactView.Locator = strLRTrim(conPeek(readCon,3));
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Delivery Fax";
contactView.Locator = strLRTrim(conPeek(readCon,4));
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
inserted++;
}
}
ttsCommit;
}
info(strfmt("%1 records inserted out of %2",inserted,icount));
}
If Dimension field on LedgerTable to be replaced with a LedgerDimension column using the LedgerDimensionAccount .
DimensionStorage dimensionStorage;
DimensionAttribute deparmentDimensionAttribute;
DimensionAttributeValue newDepartmentValue;
// Find the deparment dimension attribute
deparmentDimensionAttribute = DimensionAttribute::findByName("Department");
// Find the new department value we want to put in the new combination.
newDepartmentValue = DimensionAttributeValue::findByDimensionAttributeAndValue(deparmentDimensionAttribute, "abc");
// Load a DimensionStorage instance with the old combination and update the first segment with new value
dimensionStorage = DimensionStorage::findById(ledgerTable.LedgerDimension);
dimensionStorage.setSegment(1,DimensionStorageSegment::constructFromValue("abc", newDepartmentValue));
ledgerJournalTrans.LedgerDimension = dimensionStorage.save();
UI Builder Class in ax 2012
class ICDOCCollectorInformationUIBuilder extends SrsReportDataContractUIBuilder
{
}
public void lookupDimensionAttribute(FormStringControl /*_formControl*/_control, str _filterStr)
{
Query query;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(CollectorInformation), _control);
// Add name field to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(CollectorInformation, AgentCode));
sysTableLookup.addLookupfield(fieldNum(CollectorInformation, Employee));
sysTableLookup.addLookupfield(fieldNum(CollectorInformation, Name));
// Add the dimension attribute table as data source.
query = new Query();
query.addDataSource(tableNum(CollectorInformation));
sysTableLookup.parmQuery(query);
// Perform the lookup.
sysTableLookup.performFormLookup();
}
public void postBuild()
{
DialogField dimensionAttribute;
super();
// From binding info, get the dialog field for dimension attribute and add button
dimensionAttribute = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ICDOCCollectorInformationContract, parmAgentCode));
dimensionAttribute.label("Collector");
if (dimensionAttribute)
{
dimensionAttribute.lookupButton(2);
}
}
public void postRun()
{
Dialog dialogLocal = this.dialog();
DialogField dialogField;
super();
// This method should be called in order to handle events on dialogs.
dialogLocal.dialogForm().formRun().controlMethodOverload(false);
// Override the lookup for parmDimensionAttribute contract parameter with dimensionAttributeLookup of this class.
dialogField = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ICDOCCollectorInformationContract, parmAgentCode));
dialogField.registerOverrideMethod(
methodStr(FormStringControl, lookup),
methodStr(ICDOCCollectorInformationUIBuilder, lookupDimensionAttribute),
this);
}
class ProjHourUtilisationUIBuilder extends SysOperationAutomaticUIBuilder
{
ProjHourUtilisationContract projHourUtilisationContract;
DialogField dialogCategory;
DialogField dialogProject;
DialogField dialogEmployee;
DialogField fromDate;
DialogField toDate;
}
public void build()
{
Dialog dialogLocal = this.dialog();
projHourUtilisationContract = this.dataContractObject();
this.addDialogField(methodStr(ProjHourUtilisationContract,parmProjectId), projHourUtilisationContract);
this.addDialogField(methodStr(ProjHourUtilisationContract,parmCategory), projHourUtilisationContract);
this.addDialogField(methodStr(ProjHourUtilisationContract,parmEmployeeId), projHourUtilisationContract);
this.addDialogField(methodStr(projHourUtilisationContract,parmFromDate),projHourUtilisationContract);
this.addDialogField(methodStr(projHourUtilisationContract,parmToDate),projHourUtilisationContract);
}
public void getFromDialog()
{
projHourUtilisationContract = this.dataContractObject();
super();
}
public void initializeFields()
{
projHourUtilisationContract = this.dataContractObject();
}
public void lookupCategory(FormStringControl _control)
{
Query query = new Query();
SysTableLookup sysTablelookup;
sysTablelookup =SysTableLookup::newParameters(tableNum(ProjCategory),_control);
sysTablelookup.addLookupfield(fieldNum(ProjCategory,CategoryId));
sysTablelookup.addLookupfield(fieldnum(ProjCategory,Name));
sysTablelookup.addLookupfield(fieldnum(ProjCategory,CategoryType));
query.addDataSource(tableNum(ProjCategory));
query.dataSourceTable(tableNum(ProjCategory)).addRange(fieldNum(ProjCategory, CategoryType)).value(queryValue(ProjCategoryType::Hour));
sysTablelookup.parmQuery(query);
sysTablelookup.performFormLookup();
}
public void postRun()
{
Dialog dialogLocal = this.dialog();
super();
// This method should be called in order to handle events on dialogs.
dialogLocal.dialogForm().formRun().controlMethodOverload(false);
}
public void postBuild()
{
;
super();
dialogCategory = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ProjHourUtilisationContract,parmCategory));
// register override method for lookup customer
dialogCategory.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(ProjHourUtilisationUIBuilder,lookupCategory),this);
dialogProject = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ProjHourUtilisationContract,parmProjectId));
dialogEmployee = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ProjHourUtilisationContract,parmEmployeeId));
fromDate = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ProjHourUtilisationContract,parmFromDate));
toDate =this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(ProjHourUtilisationContract,parmToDate));
}
SysUnitTestCode- For Unit Test Classes
SysTestTargetAttribute(classstr(SysDictTable),
UtilElementType::Class)]
class PIYSysDictTableTest extends SysTestCase
{
SysDictTable SysDictTable;
public
void SetUp()
{
;
print 'Test initialization called';
}
[SysTestMethodAttribute]
public
void testTableName()
{
// Verify that the tables name is
set correctly
this.assertEquals("CustTable",
SysDictTable.name());
}
[SysTestMethodAttribute]
public
void testTableGroup()
{
// varify that the tables group is
set correctly
this.assertEquals(TableGroup::Main,
SysDictTable.tableGroup());
}
public
void teardown()
{
;
print 'Test initialization called';
}
}
public class PIYTestSuite extends SysTestSuite
{
public void new()
{
;
super();
// Set the TEST
this.add(new PIYSysDictTableTest());
}
public
static void main(Args _params)
{
// Declare Parent Suite
PIYTestSuite suite
= new PIYTestSuite();
SysTestResult result
= new SysTestResult();
//
Run the suite
result.addListener(new
SysTestListenerPrint());
suite.run(result);
print result.getSummary();
pause;
}
public
void setup()
{
;
print 'Suite initialization called';
}
public
void teardown()
{
;
print 'Suite cleanUp called';
}
}
Subscribe to:
Posts (Atom)
