Import Customer through X++

static void UploadCustomer(Args _args)
 CommaTextIO csvFile;
 container readCon;
 counter icount,inserted;
 Dialog dialog;
 DialogField dfFileName;

 FileName fileName;
 Name name;

 DirPartyContactInfoView contactView;
 CustTable CustTable;
 DirParty dirParty;
 DirPartyRecId partyRecId;

 LogisticsPostalAddress address;
 DirPartyPostalAddressView addressView;

 inserted =0;


 dialog = new Dialog("Pick the file");
 dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
 dialog.filenameLookupFilter(["All files", #AllFiles]);

 if (
 csvFile = new CommaTextIo(dfFileName.value(), 'r');
 readCon =;
 while(csvFile.status() == IO_Status::OK)
 readCon =;


 name = conPeek(readCon,2);
 partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;

 custTable.Party = partyRecId;
 custTable.AccountNum = conPeek(readCon,1);
 custTable.CustGroup = conPeek(readCon,3);
 custTable.Currency = conPeek(readCon,7);
 custTable.DlvMode = conPeek(readCon,8);
 custTable.PaymTermId = conPeek(readCon,9);

 custTable = Custtable::find(conPeek(readCon,1));
 partyRecId = custTable.Party;

 DirParty = DirParty::constructFromPartyRecId(partyRecId );
 //address.PostBox = strLRTrim(conPeek(readCon,13));
 address.CountryRegionId = strLRTrim(conPeek(readCon,5));
 if( address.CountryRegionId != "")
 address.State = strLRTrim(conPeek(readCon,15));
 address.ZipCode = strLRTrim(conPeek(readCon,15));
 address.Street = strLRTrim(conPeek(readCon,4));
 address.City = strLRTrim(conPeek(readCon,18));
 //address.Address = conPeek(readCon,4);
 addressView.LocationName = "Address";
 addressView.IsPrimary = NoYes::Yes;
 addressView.Party = partyRecId;

 DirParty = DirParty::constructFromPartyRecId(addressView.Party );


 if(conPeek(readCon,5) != "")
 contactView.LocationName = "Phone Number";
 contactView.Locator = strLRTrim(conPeek(readCon,5));
 contactView.Type = LogisticsElectronicAddressMethodType::Phone;
 contactView.Party = partyRecId;
 contactView.IsPrimary = NoYes::Yes;

 if(conPeek(readCon,3) != "")
 contactView.LocationName = "Fax Number";
 contactView.Locator = strLRTrim(conPeek(readCon,3));
 contactView.Type = LogisticsElectronicAddressMethodType::Fax;
 contactView.Party = partyRecId;
 contactView.IsPrimary = NoYes::Yes;

 if(conPeek(readCon,4) != "")
 contactView.LocationName = "Website";
 contactView.Locator = strLRTrim(conPeek(readCon,4));
 contactView.Type = LogisticsElectronicAddressMethodType::URL;
 contactView.Party = partyRecId;
 contactView.IsPrimary = NoYes::Yes;

 if(conPeek(readCon,6) != "")
 contactView.LocationName = "Email";
 contactView.Locator = strLRTrim(conPeek(readCon,6));
 contactView.Type = LogisticsElectronicAddressMethodType::Email;
 contactView.Party = partyRecId;
 contactView.IsPrimary = NoYes::Yes;




InMemory vs. TempDb

Temporary tables – InMemory vs. TempDb

The choice of whether to use a TempDB or InMemory temporary table depends on the scenario where it is used. Before using these tables the following considerations must be followed for best practice prospective.

  • Usually, TempDB temporary tables are faster than in InMemory ones.
  • Temporary tables are maintained in the database and support joins with regular tables.
  • InMemory temporary tables are instantiated in the active memory of the tier the process is running on. The process can run on the client tier or the server tier. The objects are held in memory until the size reaches 128 KB. The dataset is then written to a disk file on the server tier.
  • You can use InMemory temporary tables when the amount of data is small and Microsoft SQL Server round trips should be avoided.
  • Both InMemory and TempDb tables can be used as data sources on forms.

Note: An InMemory table cannot be joined in an X++ SQL statement with Regular/TempDB tables. It must be the outer table in a join. It is better to use TempDB temporary tables, because SQL operations are faster due to being maintained in the database. In Figure 3, you can see the TableType property for a table, where you can set the type as Regular, InMemory, or TempDB.