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 :
Finance | Project Operations, Human Resources, ...
Answered

In x++ date validation.

(0) ShareShare
ReportReport
Posted on by 130

Hi guys,

i have a two Date fields one is 'Project issuance' another one is 'Project expiry'.

my requirement is a  Project duration for 6 month.

Ex :

in Project ID < P001  <  Project issuance date<"6/25/2020"> <Project expiry<12/31/2020>

<tomorrow >

Project ID <P002   <  Project issuance date<"6/26/2020"> <Project expiry<01/01/2021>

Now, day by day based on Project ID we need to calculate date how can i write in x++.

i planned to write in OnmodifiedField. 

Thanks,

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    So do you want to validate that values that the user enters are ok according to some rule?

    Or do you want to automatically calculate Project expiry date when the user enters Project issuance date?

    In your question title you were talking about validation.

    You should use validateWrite method for most validations. You should NOT use "onModified" event for validations. It's important to put code in correct place to guarantee readability and maintainability of your code.

    Could you please try to explain your requirement once more, as clearly as possible? Thanks!

  • WaytoAx Profile Picture
    130 on at

    Thanks for you quickly replay Nikolaos Mäenpää Sir,

    yes! i want calculate Project expiryDate when the user enters Project issuance date correct.

    day by day calculate based on today date how can i get in x++ ?

    give us a example.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can use DateTimeUtil::addMonths() function to add months to a datetime variable.

  • WaytoAx Profile Picture
    130 on at

    Why! i'm used a date filed not a dateTime and in the  DateTimeUtil::addMonths(passed an utcdateTime , int) what should i do ?

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    In general I suggest using DateTime fields instead of Date fields - you can hide the time part.

    But you can of course convert your date into date time. And a date time back to date.

    www.google.com/search

  • WaytoAx Profile Picture
    130 on at

    Thanks , even if it datetime field we can't get calculate datetime in this function  DateTimeUtil::addMonths() i tried it is not working on it.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    I'm sure that the function works. It returns a DateTime with the added months. Did you remember to take the return value and use it?

    If you need help with your code, please share it.

  • WaytoAx Profile Picture
    130 on at

    thanks sir i  totally over looked it it is working fine now.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans