web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Update first name and last name in dirpersonname through X++ code

(0) ShareShare
ReportReport
Posted on by 55

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;       
}

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    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;

  • Verified answer
    chrisrojas Profile Picture
    55 on at

    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();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 495 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 315 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans