Sample code to upgrade the ContactPerson & Vendors with PartyID.
Update Contact Person-
static void krishh_ContactPersonUpdatePartyId(Args _args)
{
ContactPerson contact;
;
ttsbegin;
while select forupdate contact
where ! contact.PartyId
{
// Check if not associated to Party
if (!contact.PartyId)
{
// Create a Party entry for customer
contact.PartyId = DirParty::createPartyFromCommon(contact).PartyId;
}
else
{
DirParty::updatePartyFromCommonInsert(contact.PartyId,contact);
}
if (!contact.OrgPartyId)
{
if (contact.CustAccount)
{
contact.OrgPartyId = CustTable::find(contact.CustAccount).PartyId;
}
else
if (contact.VendAccount)
{
contact.OrgPartyId = VendTable::find(contact.VendAccount).PartyId;
}
}
else
{
if (!contact.CustAccount)
{
contact.CustAccount = CustTable::findByPartyId(contact.OrgPartyId).AccountNum;
}
if ( !contact.VendAccount)
{
contact.VendAccount = VendTable::findByPartyId(contact.OrgPartyId).AccountNum;
}
}
if (!contact.ContactPersonId)
{
contact.ContactPersonId = NumberSeq::newGetNum(CompanyInfo::numRefContactPersonId ()).num();
}
// Create relations
DirPartyRelationship::createRecordRelations(DirRelationshipTypeTable::findBySystemType(DirSystemRelationshipType::ContactPerson).RelationshipTypeId,contact.OrgPartyId,contact.PartyId);
// HRm
HRMVirtualNetworkTableReplicate_Contact::insert(contact);
}
ttscommit;
}
Update Vendors-
static void FixPartyIdForAllCompanies(Args _args)
{
VendTable vendTable;
we can do the same with the Cust Table.
// CustTable custTable;
;
try
{
WHILE SELECT forupdate
vendTable
WHERE ! vendTable.PartyId
{
ttsbegin;
info(strfmt("vend %1, %2", vendTable.AccountNum, vendTable.PartyId));
vendTable.PartyType = DirPartyType::Organization;
if (vendTable.VendGroup == 'FLICA')
vendTable.PartyType = DirPArtyType::Person;
vendTable.PartyId = DirParty::CreatePartyFromCommon(vendTable).PartyId;
if (vendTable.validateWrite())
vendTable.update(false, true);
else
warning(strfmt("Vend: %1", vendTable.AccountNum));
info(strfmt("Vend: %1", vendTable.AccountNum));
ttscommit;
}
}
catch(Exception::Error)
{
throw error("There has been and error.");
}
info("Finished");
}
Update Contact Person-
static void krishh_ContactPersonUpdatePartyId(Args _args)
{
ContactPerson contact;
;
ttsbegin;
while select forupdate contact
where ! contact.PartyId
{
// Check if not associated to Party
if (!contact.PartyId)
{
// Create a Party entry for customer
contact.PartyId = DirParty::createPartyFromCommon(contact).PartyId;
}
else
{
DirParty::updatePartyFromCommonInsert(contact.PartyId,contact);
}
if (!contact.OrgPartyId)
{
if (contact.CustAccount)
{
contact.OrgPartyId = CustTable::find(contact.CustAccount).PartyId;
}
else
if (contact.VendAccount)
{
contact.OrgPartyId = VendTable::find(contact.VendAccount).PartyId;
}
}
else
{
if (!contact.CustAccount)
{
contact.CustAccount = CustTable::findByPartyId(contact.OrgPartyId).AccountNum;
}
if ( !contact.VendAccount)
{
contact.VendAccount = VendTable::findByPartyId(contact.OrgPartyId).AccountNum;
}
}
if (!contact.ContactPersonId)
{
contact.ContactPersonId = NumberSeq::newGetNum(CompanyInfo::numRefContactPersonId ()).num();
}
// Create relations
DirPartyRelationship::createRecordRelations(DirRelationshipTypeTable::findBySystemType(DirSystemRelationshipType::ContactPerson).RelationshipTypeId,contact.OrgPartyId,contact.PartyId);
// HRm
HRMVirtualNetworkTableReplicate_Contact::insert(contact);
}
ttscommit;
}
Update Vendors-
static void FixPartyIdForAllCompanies(Args _args)
{
VendTable vendTable;
we can do the same with the Cust Table.
// CustTable custTable;
;
try
{
WHILE SELECT forupdate
vendTable
WHERE ! vendTable.PartyId
{
ttsbegin;
info(strfmt("vend %1, %2", vendTable.AccountNum, vendTable.PartyId));
vendTable.PartyType = DirPartyType::Organization;
if (vendTable.VendGroup == 'FLICA')
vendTable.PartyType = DirPArtyType::Person;
vendTable.PartyId = DirParty::CreatePartyFromCommon(vendTable).PartyId;
if (vendTable.validateWrite())
vendTable.update(false, true);
else
warning(strfmt("Vend: %1", vendTable.AccountNum));
info(strfmt("Vend: %1", vendTable.AccountNum));
ttscommit;
}
}
catch(Exception::Error)
{
throw error("There has been and error.");
}
info("Finished");
}
No comments:
Post a Comment
Thanks for visiting my blog,
I will reply for your comment within 48 hours.
Thanks,
krishna.