Thursday, 17 January 2019

create or update customer along with details through x++

static void CreateAndUpdateCustomer(Args _args)
{
LogisticsElectronicAddress logisticselectronicaddress;
LogisticsContactInfoView logisticsContactInfoView;
LogisticsPostalAddress logisticspostaladdress;
LogisticsLocation logisticslocation;
CustTable custTable;
DirParty dirParty;
DirPartyLocation dirPartyLocation;
DirPartyContactInfoView dirPartyContactInfo;
DirPartyTable dirPartyTable;

ContactPerson contactperson;

DirPartyPostalAddressView dirPartyPostalAddressView;

AccountNum accountNum = ‘Test_10′;
CustGroupId custGroupId = ’10’;
Name name = ‘Test_10’;

custTable = CustTable::find(accountNum);

if(!custTable) // if customer not exits
{

ttsBegin;
custTable.clear();
custTable.initValue();

custTable.AccountNum = accountNum;
custTable.CustGroup = custGroupId;

custTable.insert(DirPartyType::Organization, name);

dirParty = DirParty::constructFromCommon(custTable);

dirPartyPostalAddressView.LocationName = ‘Test_10’;
dirPartyPostalAddressView.City = ‘Karmimnagar’;
dirPartyPostalAddressView.Street = ‘Towercircle’;
dirPartyPostalAddressView.StreetNumber = ‘123’;
dirPartyPostalAddressView.CountryRegionId = ‘IND’;

dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
// inserting phone number details
dirPartyContactInfo.LocationName = ‘SouthStreet Contact Phone’;
dirPartyContactInfo.Locator = ‘55125341’;
dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Phone;
dirPartyContactInfo.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
// inserting email details
dirPartyContactInfo.LocationName = ‘SouthStreet Contact email’;
dirPartyContactInfo.Locator = ‘soth@gmail.com’;
dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Email;
dirPartyContactInfo.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
// inserting fax details
dirPartyContactInfo.LocationName = ‘SouthStreet Contact fax’;
dirPartyContactInfo.Locator = ‘+91451’;
dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Fax;
dirPartyContactInfo.IsPrimary = NoYes::Yes;

// Fill Contacts
dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
ttsCommit;
}

else
{
custTable = CustTable::find(accountNum); //if customer exist

dirParty = DirParty::constructFromCommon(custTable);

while select dirPartyLocation
where dirPartyLocation.Party == custTable.Party
join dirPartyPostalAddressView
where dirPartyPostalAddressView.Location == dirPartyLocation.Location
&& dirPartyPostalAddressView.Party == dirPartyLocation.Party
{
dirPartyPostalAddressView.LocationName = ‘Hyderabad2 ‘;
dirPartyPostalAddressView.City = ‘Hyderabad2’;
dirPartyPostalAddressView.Street = ‘HUda colony2′;
dirPartyPostalAddressView.StreetNumber = ’22’;
dirPartyPostalAddressView.CountryRegionId = ‘IND’;
dirPartyPostalAddressView.IsPrimary = 1;
dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

}
//for updating email address
while select dirPartyLocation
where dirPartyLocation.Party == custTable.Party
{
logisticslocation = logisticslocation::find(dirPartyLocation.Location);
while select forUpdate logisticselectronicaddress
where logisticselectronicaddress.Location == logisticslocation.RecId
&& logisticselectronicaddress.Type == LogisticsElectronicAddressMethodType::Email
&& logisticselectronicaddress.IsPrimary == NoYes::Yes
{
//info(strFmt(“%1”,logisticselectronicaddress.Locator));
ttsBegin;

logisticselectronicaddress.Locator = “Test@gmail2.com”;
logisticselectronicaddress.IsPrimary = NoYes::Yes;
logisticselectronicaddress.update();
info(strFmt(“%1”,logisticselectronicaddress.Locator));

ttsCommit;
}
}
//for updating phone number
while select dirPartyLocation
where dirPartyLocation.Party == custTable.Party
{
logisticslocation = logisticslocation::find(dirPartyLocation.Location);
while select forUpdate logisticselectronicaddress
where logisticselectronicaddress.Location == logisticslocation.RecId
&& logisticselectronicaddress.Type == LogisticsElectronicAddressMethodType::Phone
&& logisticselectronicaddress.IsPrimary == NoYes::Yes
{
//info(strFmt(“%1”,logisticselectronicaddress.Locator));
ttsBegin;

logisticselectronicaddress.Locator = “989898989”;
logisticselectronicaddress.IsPrimary = NoYes::Yes;
logisticselectronicaddress.update();
info(strFmt(“%1”,logisticselectronicaddress.Locator));

ttsCommit;
}
}
//for updating Fax number
while select dirPartyLocation
where dirPartyLocation.Party == custTable.Party
{
logisticslocation = logisticslocation::find(dirPartyLocation.Location);
while select forUpdate logisticselectronicaddress
where logisticselectronicaddress.Location == logisticslocation.RecId
&& logisticselectronicaddress.Type == LogisticsElectronicAddressMethodType::Fax
&& logisticselectronicaddress.IsPrimary == NoYes::Yes
{
ttsBegin;

logisticselectronicaddress.Locator = “2578”;
logisticselectronicaddress.IsPrimary = NoYes::Yes;
logisticselectronicaddress.update();
info(strFmt(“%1”,logisticselectronicaddress.Locator));

ttsCommit;
}
}
}
}

No comments:

Post a Comment