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, ...
Suggested Answer

DirPersonName ValidFrom is not filled automatically by code

(3) ShareShare
ReportReport
Posted on by 172
Hi,

When we create a contact person for a customer manually, then DirPersonName.ValidFrom field gets filled automatically.

However, if we i do it by code, the validFrom field in DirPersonName is not filled
 
  smmContactPersonV2Entity.ContactPersonId                = _contract.ContactPersonId();
  smmContactPersonV2Entity.AssociatedPartyNumber          = _contract.AssociatedPartyNumber();
  smmContactPersonV2Entity.ContactPersonPartyType         = enum2Str(DirPartyType::Person);  
  smmContactPersonV2Entity.FirstName                      = _contract.FirstName();   
  smmContactPersonV2Entity.ContactForParty                = DirPartyTable::find(_contract.AssociatedPartyNumber()).RecId;

  smmContactPersonV2Entity.insert();
 
 
is there a method i need to call?
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    Do you mean that you want to explicitly set the data as invalid before the current time?
     
    Please tell us what steps you do in GUI.
     
    You're using an entity - what behaviour do you see when you import the data through data management? You'll see whether it's the normal behavior of the entity or the problem is caused by your code.
     
    Will it make any difference if you call initValue()?
  • Suggested answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at
    it appears that while the record is created from the UI, it goes through 
    DirPartyBaseEntity >> insertEntityDataSource >> postUpdatePartyBuffer >>
    and this is where the ValidFrom and ValidTo are initialized
     
     
    If values for these fields are not being provided  to entity field, it will take Max and Now values as above:
     
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    I wonder the GUI for contact persons really use data entities. smmContactPerson form, for example, uses ContactPerson table as the data source, not smmContactPersonV2Entity.
     
    Nevertheless Sohaib's finding suggest that DirPersonName.ValidFrom is expected to be initialized in the current time if a new record is being inserted. Debug the code to see why it doesn't execute in your case.
  • CU22120935-0 Profile Picture
    172 on at
    Hi All, 

    From the UI, i just go to customers, view contacts, create new contact (fill first name and last name)
    I go to the DB and see that DirPersonName.ValidFrom gets filled with current date time.

    Using entity.initValue() doesn't make a difference, still DirPersonName.ValidFrom is empty (1900)
     
    DirPartyBaseEntity  doesn'r get called from the UI
     
     
    In the code i'm trying with the entity, I debugged and I saw it doesn't enter the code that Sohaib mentioned because of savedPersonName= No



    Even though initValue in dirPartyBaseEntity is yes
     
    there is code later that makes savedPersonName as No in mapEntityToDataSource method, which gets called before the code that Sohaib mentioned
     
     
    What is this field savePersonName? and why does it become false later? and how to overcome it?
     
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    DirPersonBaseEntity has DirPersonName as a data source, so it doesn't want DirPartyBaseEntity to try to save the same thing again.
  • CU22120935-0 Profile Picture
    172 on at
     
    What do u mean it doesn't want to save the same thing again? u mean it will create another party or what?

    and how to make my code matches standard behavior?
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    I'm saying that DirPersonName table is already handled by DirPersonBaseEntity, therefore DirPartyBaseEntity shouldn't try to do the same. That's why DirPersonBaseEntity uses DirPartyBaseEntity.SavePersonName = No to pass this information to DirPartyBaseEntity.
  • CU22120935-0 Profile Picture
    172 on at
    Hi @Martin Dráb,

    Then how to fix my issue?
    shall i fill it by code when inserting saying validFrom = utc::Now?
  • CU22120935-0 Profile Picture
    172 on at
    Any help please? @Martin Dráb

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 659

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 304 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans