Hello,
I'm new in Dynamics 365 for finance and operations.
I have to update the first name and last name of a customer of type person, using x code.
I found that the fields FirstName and LastName are stored in the table DirPersonName. I tried the code below, but the name is not being updated.
Can anyone help me?
CustTable custTable;
DirPartyTable dirPartyTable;
DirPersonName dirPersonName;
DirPerson dirPerson;
AccountNum accountNum;
FirstName firstName;
LastName lastName;
date dateFrom,
dateTo;
custTable = CustTable::find(accountNum, true);
if(custTable)
{
ttsbegin;
select forupdate dirPartyTable
where dirPartyTable.RecId == custTable.Party;
if(dirPartyTable.partyType() == dirPartyType::Person)
{
select forupdate dirPerson
where dirPerson.PartyNumber == dirPartyTable.PartyNumber;
if(dirPerson)
{
datefrom = 01\01\1900;
dateTo = 31\12\2154;
select forupdate validtimestate(dateFrom, dateTo) * from dirPersonName
where dirPersonName.Person == dirPerson.RecId;
if(dirPersonName)
{
info(strFmt("update dirpersonname %1",firstName));
dirPersonName.FirstName = firstName;
dirPersonName.LastName = lastName;
dirperson.updateName(dirPersonName);
dirPerson.update();
}
}
}
ttscommit;
}