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

MS CRM 2015 Calculated Fields with remaining Month left in current year

(0) ShareShare
ReportReport
Posted on by 943

We have one requirement on MS CRM Express mobile forms. 

For Example I have one random date  (13-July-2015) in MS CRM 2015 Express forms. So with the help of calculated field date functions I would like to get remaining months left in current year (in this case the answer is 5) .  This 5 value I need to use in some other calculation. Kindly help me to get remaining month for the current year from the any date of current year.

Kindly suggest some formula.

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at

    Hi Varun,

    Try this code:

    function calMonths() {

       //get the Calculated field value in variable

       var startday = xrm.page.getAttribute( "calculatedfieldname").getValue();

       // get todays date in variable

       var today = new date();

       // get the value of one day in (mili_second * second * min * hours)

       var one_dat = 1000 * 60 * 60 * 24;

       // get no of days in month

       var one_month = 30;

       //get time

       var starttime = startday.getTime();

       var currenttime = today.getTime();

       var diffrence = math.abs(currenttime - starttime);

       noofdays = Math.round(diffrence / one_day);

       noofmonths = Math.round(noofdays / one_month);

       // set the noofmonths value in field

       xrm.page.getAttribute( "new_calmonths").setValue(noofmonths);

    }

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"  

  • Varun Singh Profile Picture
    943 on at

    Hi Raj,

    XRM.Page script won't work on Mobile express form. That is why I wanted help of calculated fields. Mobile Express are stand alone application where JavaScript wont work.

    We can apply JavaScript only for web client.

  • ScottDurow Profile Picture
    21 on at

    In CRM 2015 Update 1 you can use DiffInMonths against Now() to calculate this - e.g.

    DIFFINMONTHS(<yourdatefield>,NOW())

    See:

    technet.microsoft.com/.../dn832103.aspx

    If you are using CRM OnPrem then you will have to wait until the end of this year to get this feature.

    Hope this helps,

    Scott

  • Varun Singh Profile Picture
    943 on at

    Hi Scott,

    I think think it won't work because I need remaining month left for this year from any random date. Your answer will give only month difference between today date and a random date.

  • Varun Singh Profile Picture
    943 on at

    For Example I have one random date  (13-July-2015) in MS CRM 2015 Express forms. So with the help of calculated field date functions I would like to get remaining months left in current year (in this case the answer is 5) .  This 5 value I need to use in some other calculation.

  • ScottDurow Profile Picture
    21 on at

    I understand. You would need another date field that specifies the date of the end of the year - then you could use the DIFFINMONTHS. You could set this field on create of the record.

  • Varun Singh Profile Picture
    943 on at

    HI Scott,

    This is also not possible for Mobile express form I think. Suppose some buddy wanted opened new form off Opportunity in Mobile. Then how can we set a field with date (For ex 31-Dec-2015) on the opening of the form in real time.

  • Varun Singh Profile Picture
    943 on at

    Yes Guido,

    I have thought of that but business want in real time like JavaScript do.

    There is one more problem from the technical point of view.This remaining month I need to use in big formula. So each time I am changing any of the field in the formula the plugin will fire and change the value unnecessary.

  • ScottDurow Profile Picture
    21 on at

    You would set the date on the server side when - no the client side.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans