Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript recurrence function help

Posted on by Microsoft Employee

I have a function which calculates amount taking two dates booking from and booking to.

I want to use the same function to calculate the amount taking two new fields.

*This post is locked for comments

  • RE: Javascript recurrence function help

    If you're planning on having different output fields for this date calculation you could add a third parameter for output, so that your function would look something like this:

    function CalculateDays(start, end, output)


    If you'r on v9 you should also pass the execution context as the first parameter.

    function CalculateDays(executionContext, start, end, output)

    Xrm.Page-model is deprecated, and using the execution context is the the way to do this properly.

    OOTB Calculated fields as suggested by Khoa Nguyen is also a good option as it is a no-code solution.

  • Suggested answer
    Clem Profile Picture
    Clem 2,541 on at
    RE: Javascript recurrence function help

    if your initial function looks like the one posted by Alex.

    You can add an extra parameter, something like :

    function CalcData(field1, field2, isField = true)

    {

    if(isField){

      var attribute1= Xrm.Page.getAttribute(field1);

      var attribute2= Xrm.Page.getAttribute(field2);

    }

    else

    var attribute1= field1; (a date value)

       var attribute2= field2; (a date value)

      //Do the calculations

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript recurrence function help

    Yes, I have another field of called Reschedule, If it is yes we are asking the user to enter two new dates to and from. I want to calculate the amount using the same function by sending new dates.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Javascript recurrence function help

    Are you asking how to pass parameters?

    function CalcData(field1, field2)

    {

       var attribute1= Xrm.Page.getAttribute(field1);

       var attribute2= Xrm.Page.getAttribute(field2);

       //Do the calculations

    }

    Then call it with different field names:

    CalcData("new_field1", "new_field2");

  • Suggested answer
    khoait Profile Picture
    khoait 450 on at
    RE: Javascript recurrence function help

    Hi Alekya,

    You may want to have a look at OOTB Calculated field: technet.microsoft.com/.../dn832103.aspx

  • Clem Profile Picture
    Clem 2,541 on at
    RE: Javascript recurrence function help

    Can you please give us a bit more details of what you are trying to achieve ?

    If i got it right, you have 2 parameters : From and To and based on these 2 dates, you calculates the amount of money for all opportunities opened or closed during this time frame ?

    What do you mean by "two new fields" ? two new dates ?

    Regards,

    Clément

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans