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 CRM (Archived)

re-creating the 'duration in days' field from Contracts on another entity

(0) ShareShare
ReportReport
Posted on by 180

Hi

On the contracts entity there is a field called duration in days which auto calcuates the difference between the start and end date. I want to have this on another entity but i don;t know the code to be able to replicate this. Can someone give me the code needed to recreate this field?

thanks!

*This post is locked for comments

I have the same question (0)
  • alf Profile Picture
    17,915 on at

    Hi Suzy,

    Create a new field of type 'int' and format 'duration'.

  • suzi Thurston Profile Picture
    180 on at

    Hi

    If I do this as you suggest I get a picklist with mins and days as options which is not right. What I need is the exact same concept as in 'Contracts' where the duration will be automatically filled once I enter a start and end date. I need it to show the duration in days between these two values.

    please advise if you can help

    thanks!

    suzi

  • Verified answer
    Jeremy Winchell Profile Picture
    1,165 on at

    Suzi,

    There are a couple of ways you can go about this:

    1. You can use JavaScript to calculate this value on the entity:

      - Issue:  This only works when the record is opened/saved so it won't change on a daily basis

      -  There are quite a few examples of code on the web that will help you get there, if you decide to use this method.

    2. You can use a workflow that runs daily to calculate this field

      - Issue:  Depending on the # of records that the workflows are running on, it could cause performance related issues.

    3. You could use an integration tool like Scribe to run each night and update this field behind the scenes.

      - This is probably the best option because it will not introduce issues that were outlined in option 1 or 2.

    Thanks,

    Jeremy

  • Verified answer
    Jeremy Winchell Profile Picture
    1,165 on at

    Suzi,

    To build on what Alex had posted here is some JavaScript that would help populate the Duration Field that Alex suggested that you setup:

    var _sdate = crmForm.all.new_entity.new_startdatefield.DataValue;

    var _edate = crmForm.all.new_entity.new_enddatefield.DataValue;

    crmForm.all.SOME_DURATION_FIELD_ID.DataValue = _edate.getTime() - _sdate.GetTime() should give you the duration.

    Jeremy

  • suzi Thurston Profile Picture
    180 on at

    thank you Jeremy, i have now solved this issue. Many thanks for your help, much appreciated

  • Jeremy Winchell Profile Picture
    1,165 on at

    Not a problem Suzi, glad I was able to help out.  If you could, can you mark this question as answered in the community?

    Thanks,

    Jeremy Winchell

    Inetium

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans