Hi all
I import customers from one company to another through this code but I did not have addresses. Where I wrong.? Is there anyone who help me.?
static void AXP_ImportCustomersFromBSIToPTY(Args _args)
{
custTable custTablelocal, custTablePTY, custTableValidation;
DirPartyTable DirPartyTablelocal, DirPartyTablePTY;
DirPersonPartyDetail DirPersonPartyDetaillocal, DirPersonPartyDetailPTY;
DirOrganizationDetail DirOrganizationDetaillocal, DirOrganizationDetailPTY;
DirPartyAddressRelationship DirPartyAddressRelationshiplocal, DirPartyAddressRelationshipPTY;
DirPartyAddressRelationshipMapping DirPartyAddressRelationshipMappinglocal, DirPartyAddressRelationshipMappingPTY;
Address Addresslocal, AddressPTY;
DirPartyECommunicationRelationship DirPartyECommunicationRelationshiplocal, DirPartyECommunicationRelationshipPTY;
DirPrivacyGroupTable DirPrivacyGroupTablelocal, DirPrivacyGroupTablePTY;
DirECommunicationAddress DirECommunicationAddresslocal, DirECommunicationAddressPTY;
str CompanyId;
int NoOfRecords;
boolean a = true ;
;
CompanyId = curExt();
while select custTablelocal
where //custTablelocal.AccountNum like "A*"
custTablelocal.AccountNum == "AA002A"
{
select DirPartyTablelocal
where DirPartyTablelocal.PartyId == custTablelocal.PartyId;
if(DirPartyTablelocal)
{
select DirPersonPartyDetaillocal
where DirPersonPartyDetaillocal.PartyId == DirPartyTablelocal.PartyId;
select DirOrganizationDetaillocal
where DirOrganizationDetaillocal.PartyId == DirPartyTablelocal.PartyId;
select DirPartyAddressRelationshiplocal
where DirPartyAddressRelationshiplocal.PartyId == DirPartyTablelocal.PartyId;
if(DirPartyAddressRelationshiplocal)
{
select DirPartyAddressRelationshipMappinglocal
where DirPartyAddressRelationshipMappinglocal.PartyAddressRelationshipRecId == DirPartyAddressRelationshiplocal.RecId
&& DirPartyAddressRelationshipMappinglocal.RefCompanyId == 'bsi';
}
select DirPartyECommunicationRelationshiplocal
where DirPartyECommunicationRelationshiplocal.PartyId == DirPartyTablelocal.PartyId;
if(DirPartyECommunicationRelationshiplocal)
{
select DirPrivacyGroupTablelocal
where DirPrivacyGroupTablelocal.IsCustomer == NoYes::Yes
&& DirPrivacyGroupTablelocal.PrivacyGroupId == DirPartyECommunicationRelationshiplocal.PrivacyGroupId;
select DirECommunicationAddresslocal
where DirECommunicationAddresslocal.RecId == DirPartyECommunicationRelationshiplocal.ValuesRecId;
}
}
changeCompany("PTY")
{
CompanyId = curExt();
ttsbegin;
select custTableValidation
where custTableValidation.AccountNum == custTablelocal.AccountNum;
if(!custTableValidation)
{
try
{
NoOfRecords++;
try
{
custTablePTY = null;
//custTablePTY = custTablelocal;
buf2buf(custTablelocal, custTablePTY);
custTablePTY.insert();
info("Record inserted");
info(strfmt(custTablePTY.AccountNum));
}
catch
{
a = false;
info(strfmt(custTablePTY.AccountNum));
}
if(a== true)
{
try
{
DirPartyTablePTY = null;
buf2buf(DirPartyTablelocal, DirPartyTablePTY);
//DirPartyTablePTY = DirPartyTablelocal;
DirPartyTablePTY.insert();
}
catch
{
info(strfmt(DirPartyTablePTY.PartyId));
}
if(DirPersonPartyDetaillocal)
{
DirPersonPartyDetailPTY = null;
buf2buf(DirPersonPartyDetaillocal, DirPersonPartyDetailPTY);
DirPersonPartyDetailPTY.insert();
}
if(DirOrganizationDetaillocal)
{
DirOrganizationDetailPTY = null;
buf2buf(DirOrganizationDetaillocal, DirOrganizationDetailPTY);
//DirOrganizationDetailPTY = DirOrganizationDetaillocal;
DirOrganizationDetailPTY.insert();
}
if(DirPartyAddressRelationshiplocal)
{
DirPartyAddressRelationshipPTY = null;
buf2buf(DirPartyAddressRelationshiplocal, DirPartyAddressRelationshipPTY);
//DirPartyAddressRelationshipPTY = DirPartyAddressRelationshiplocal;
DirPartyAddressRelationshipPTY.insert();
}
if(DirPartyAddressRelationshipMappinglocal)
{
DirPartyAddressRelationshipMappingPTY = null;
buf2buf(DirPartyAddressRelationshipMappinglocal, DirPartyAddressRelationshipMappingPTY);
//DirPartyAddressRelationshipMappingPTY = DirPartyAddressRelationshipMappinglocal;
DirPartyAddressRelationshipMappingPTY.insert();
changeCompany("ak")
{
while select Addresslocal
where Addresslocal.dataAreaId == /*bsi*/DirPartyAddressRelationshipMappinglocal.RefCompanyId
&& Addresslocal.RecId == DirPartyAddressRelationshipMappinglocal.AddressRecId
&& (Addresslocal.AddrTableId == 77
|| Addresslocal.AddrTableId == 2303 )
{
changeCompany("PTY")
{
AddressPTY = null;
buf2buf(Addresslocal, AddressPTY);
//AddressPTY = Addresslocal;
AddressPTY.insert();
}
}
}
}
/*if(AddressPTY)
{
AddressPTY.insert();
}*/
if(DirPartyECommunicationRelationshiplocal)
{
DirPartyECommunicationRelationshipPTY = null;
buf2buf(DirPartyECommunicationRelationshiplocal, DirPartyECommunicationRelationshipPTY);
//DirPartyECommunicationRelationshipPTY = DirPartyECommunicationRelationshiplocal;
DirPartyECommunicationRelationshipPTY.insert();
}
DirPrivacyGroupTablePTY = null;
select DirPrivacyGroupTablePTY
where DirPrivacyGroupTablelocal.IsCustomer == NoYes::Yes
&& DirPrivacyGroupTablelocal.PrivacyGroupId == DirPartyECommunicationRelationshiplocal.PrivacyGroupId;
if(!DirPrivacyGroupTablePTY)
{
DirPrivacyGroupTablePTY = null;
buf2buf(DirPrivacyGroupTablelocal, DirPrivacyGroupTablePTY);
//DirPrivacyGroupTablePTY = DirPrivacyGroupTablelocal;
DirPrivacyGroupTablePTY.insert();
}
if(DirECommunicationAddresslocal)
{
DirECommunicationAddressPTY =null;
buf2buf(DirECommunicationAddresslocal, DirECommunicationAddressPTY);
//DirECommunicationAddressPTY = DirECommunicationAddresslocal;
DirECommunicationAddressPTY.insert();
}
}
}
catch
{
info("Insertion Errorr");
info(strfmt(custTablePTY.AccountNum));
}
ttsCommit;
}
}
}
//}
info(strfmt("%1", NoOfRecords));
}