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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Initialize table in X++

(0) ShareShare
ReportReport
Posted on by 504

initialize.png

Hi All,

i want to initialize this hcmpersondetails table . because i want to update its fields. without initialzing, values are loading in table but they are not showing up in form. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    If you initialize values on the buffer bound to the form datasource, then without saving a record on the current buffer, you could try to call refresh, which should render the values onto your form.

    kashperuk.blogspot.hu/.../tutorial-reread-refresh-research.html

    www.theaxapta.com/.../differences-among-reread-refreshresearch.html

    If the record changes are saved to the database, then depending on your situation you could do a reread/research/executeQuery depending on whether you have child datasources, or not.

  • xain Profile Picture
    504 on at

    Hi

    This is my code.

    HcmWorker = hcmWorker::findByPersonnelNumber(personalNumber,true);

                   if(hcmworker::findByPersonnelNumber(personalNumber))

                   {

                      if(hcmWorker.Person)

                       {

                       dirPartyTable = dirPartyTable::find(dirPerson::find(HcmWorker.Person).PartyNumber);

                       if(!dirPartyTable)

                       {

                           dirPartyTable = DirPartyTable::createNew(DirPartyType::Person,vendorName);

                       }

                       else

                       {

                           dirPersonName = DirPersonName::find(hcmWorker.Person,true);

                           dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);

                           dirPersonName.FirstName = firstName;

                           dirPersonName.LastName  = lastName;

                           dirPersonName.write();

                       }

                       }

                       ttsBegin;

                       dirPerson = dirPerson::find(DirPartyTable.RecId, true);

                      // dirPerson.MaritalStatus = maritalStatus;

                       dirPerson.write();

                       HcmWorker.Person = dirPerson.RecId;

                       HcmWorker.write();

                        HcmPersonDetails.initValue();

                       HcmPersonDetails = HcmPersonDetails::findByPerson(dirPerson.RecId);

                       //if(!HcmPersonDetails.RecId)

                       //{

                          //break;

                       //}

                       hcmPersonDetails.selectForUpdate(true);

                       HcmPersonDetails.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);

                       HcmPersonDetails.Person            = dirPerson.RecId;

                       hcmPersonDetails.MaritalStatus     = maritalStatus;

                       hcmPersonDetails.NumberOfDependents= noOfDependent;

                       hcmPersonDetails.write();

    what is wrong in this. can u specify. Thanks

  • Vilmos Kintera Profile Picture
    46,149 on at

    In what context is the above code being called, in relation to the form where you want to display the values?

  • xain Profile Picture
    504 on at

    i want to display values in employee master data. employee data is there but i want to update their marital status and numberOfDependent Values

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    I just fixed your code in a job to update hcmPersonDetails tables.

    static void AXC_Party(Args _args)
    {
        HcmWorker hcmWorker;
        dirPartyTable dirPartyTable;
        dirPersonName dirPersonName;
        str personalNumber = "123";
        str vendorName;
        str firstName, lastName;
        dirPerson dirPerson;
        HcmPersonDetails HcmPersonDetails;    
        HcmPersonMaritalStatus maritalStatus = HcmPersonMaritalStatus::Married;
        int noOfDependent;
        
        hcmworker = hcmWorker::findByPersonnelNumber(personalNumber,true);
        
        if(hcmworker.Person)
        {
            dirPartyTable = dirPartyTable::find(dirPerson::find(hcmworker.Person).PartyNumber);
        
            if(!dirPartyTable)
            {
                dirPartyTable = DirPartyTable::createNew(DirPartyType::Person, vendorName);
            }
            else
            {
                dirPersonName = DirPersonName::find(hcmWorker.Person,true);
                dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                dirPersonName.FirstName = firstName;
                dirPersonName.LastName  = lastName;
                dirPersonName.write();
            }
        }
        
        ttsBegin;
        dirPerson = dirPerson::find(DirPartyTable.RecId, true);
        dirPerson.MaritalStatus = maritalStatus;
        dirPerson.write();
        ttsCommit;
        
        HcmPersonDetails = HcmPersonDetails::findByPerson(dirPerson.RecId);
        if (HcmPersonDetails.RecId)
        {
            ttsBegin;
            hcmPersonDetails.selectForUpdate(true);
            HcmPersonDetails.initValue();
            HcmPersonDetails.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            HcmPersonDetails.Person            = dirPerson.RecId;
            hcmPersonDetails.MaritalStatus     = maritalStatus;
            hcmPersonDetails.NumberOfDependents= noOfDependent;
            hcmPersonDetails.update();
            ttsCommit;
        }
    }
  • xain Profile Picture
    504 on at

    Hi 

    i tried the changes that u have made. but it says cannot update because record never selected. which is true because there is no record in hcmpersondetails table.  recordupd.png

    so how can i solve that problem. Thanks

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    I think you haven't used my code completely, as there is an if condition and you will not get this error in first place. I am referring to below code

     HcmPersonDetails = HcmPersonDetails::findByPerson(dirPerson.RecId);    
        if (HcmPersonDetails.RecId)

    Anyway, I was thinking you are trying to update the values please use below code

        ttsBegin;
        dirPerson = dirPerson::find(DirPartyTable.RecId, true);
        dirPerson.MaritalStatus = maritalStatus;
        dirPerson.write();
    
        HcmPersonDetails.initValue();
        HcmPersonDetails.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
        HcmPersonDetails.ValidFrom = DateTimeUtil::utcNow();
        HcmPersonDetails.ValidTo = DateTimeUtil::maxValue();
        HcmPersonDetails.Person            = dirPerson.RecId;
        hcmPersonDetails.MaritalStatus     = maritalStatus;
        hcmPersonDetails.NumberOfDependents= noOfDependent;
        hcmPersonDetails.write();
        ttsCommit;


  • xain Profile Picture
    504 on at

    Hi Chaitanya Golla,

    Thanks a million , u saved my day...

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans