Hi,
If you want to add a postal address in D365 FnO against party. or DirPartyTable. My use case was while creating a HCMApplicant we need to make sure that applicant address must be created. Thus the link between them is the Party associated with HCMApplicant. and once that partyrecid is available you can create an address based on it.
public static void createPartyAddress()
{
DirPartyRecId partyRecId = DirPartyTable::createNew( DirPartyType::Person, "Firstname+middlename+lastname").RecId
//Note Here I am assuming that partyRecId is also associated with HCMApplicant and not showing code of HCMAppliation table here.
DirPartyTable dirPartyTable= DirPartyTable::findRec(partyRecId);
DirParty dirParty; DirPartyPostalAddressView dirPartyPostalAddressView;
// Create instance of dirParty
dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType());
// Create primary address
dirPartyPostalAddressView.LocationName = "Address";
dirPartyPostalAddressView.City = "Lahore";
dirPartyPostalAddressView.Street = "One Microsoft Way";
dirPartyPostalAddressView.StreetNumber = "18";
dirPartyPostalAddressView.CountryRegionId = "PAK";
dirPartyPostalAddressView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
}