Announcements
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; }
Hi, Gunjan.
Thanks for answering my question, I tried the code that you suggested but I got the same results.
It finally worked by replacing this code:
dirperson.updateName(dirPersonName); dirPerson.update();
With this one:
dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction); dirPersonName.update();
Hi Chris,
Did you debug your code to check if all the select statements are fetching the correct record and your update statement is getting called?
Looking at your code, I think the issue could be with the select statement for dirPersonName. Please check this link to see how update operations can be performed using validtimeState.
You can try this statement instead and see if the record gets updated. This will select the valid record as of today.
Date currDate = systemDateGet(); select forupdate validtimestate(currDate) * from dirPersonName where dirPersonName.Person == dirPerson.RecId;
André Arnaud de Cal...
294,217
Super User 2025 Season 1
Martin Dráb
232,978
Most Valuable Professional
nmaenpaa
101,158
Moderator