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)

Creating a field to calculate difference from old value to new value

(0) ShareShare
ReportReport
Posted on by 690

We have a field that holds the number of shares an account has. Once a user changes this number of shares, I want another field (Share Change for example) to automatically calculate the difference between the old value and the new value. I didn't see a way to do this as a workflow, any ideas? I know that auditing history captures old value vs. new value, is there a way to manipulate this data in CRM?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Karth Profile Picture
    on at

    You wouldn't be able to do it through the OOB workflows. You should be able to achieve this though plugins. The business logic within your plugin will retrieve the previous value stored in the PreImage and the new value stored in the PostImage. You then then call the update method to update the differential value on the new field.

    The other option would be to do it through javascript. But note that the javascript will fire only if you change the value through UI and wouldn't work if this changes through Integration.

  • Graham.Davis Profile Picture
    on at

    You could do it with JavaScript?

    Simply add a third (shadow) field which is hidden on the form. Always populate this field with the value of the Shares field using the onLoad event. then when a user changes the Shares field, an onChange event would have access to the new value, and the old value because it would be populated into the hidden field.

  • Suggested answer
    Talsim Profile Picture
    on at

    You can do that through a workflow with no coding needed:

    1. add a new temp field (so 3 fields : the field storing the new value, the field storing the difference and the temp)

    temp will store the current  data before it was changed. after populating  the calculation field, the temp field will be updated to the current new data:

    first step: temp field and difference are empty.

    2. initialize: if the difference field and temp field are empty  (do not contain data)

                                 then temp and difference fields gets the new value

    3.  else if the temp field contains data:

                    update diffrence = new value field - temp field //temp stores the old value

                     update  temp= new value field  // now temp will store the currentdata for the next update

    end workflow.

  • dso Profile Picture
    690 on at

    For this workflow method, how would I calculate the subtraction of "new value field - temp field." In the workflow I only see options to Set To, Increment By, Decrement By. Am I able to type in a hyphen between two values and have CRM recognize it as a subtraction calculation?

  • Graham.Davis Profile Picture
    on at

    You will not be able to do it with out-of-the-box workflows. But the manipulation library which you can get here - manipulationlibrary.codeplex.com works extremely well and is super simple to get up and running.

  • dso Profile Picture
    690 on at

    This looks like a good tool, but I noticed the library was built for CRM 2011. Is there anything out there for CRM 2013? Or do you happen to know if it will work for CRM 2013?

  • dso Profile Picture
    690 on at

    The documentation says that manipulation library is only for On Premise users. I'm using CRM 2013 Online. Any other recommendations? How about the JavaScript route? Can someone walk me through that?

  • dso Profile Picture
    690 on at

    I don't see the onLoad event as an option in the Events section of the field. Is this something I have to put into the JavaScript code manually?

  • Talsim Profile Picture
    on at

    Easy:

    set diffrence = new value

    decrement diffrence by temp

    set temp = new value

  • Talsim Profile Picture
    on at

    For this workflow method, how would I calculate the subtraction of "new value field - temp field." In the workflow I only see options to Set To, Increment By, Decrement By. Am I able to type in a hyphen between two values and have CRM recognize it as a subtraction calculation?

    ------

    That Easy:

    set diffrence = new value

    decrement diffrence by temp

    set temp = new value

    ----------

    You can do that through a workflow with no coding needed:

    1. add a new temp field (so 3 fields : the field storing the new value, the field storing the difference and the temp)

    temp will store the current  data before it was changed. after populating  the calculation field, the temp field will be updated to the current new data:

    first step: temp field and difference are empty.

    2. initialize: if the difference field and temp field are empty  (do not contain data)

                                then temp and difference fields gets the new value

    3.  else if the temp field contains data:

                   update diffrence = new value field - temp field //temp stores the old value

                    update  temp= new value field  // now temp will store the currentdata for the next update

    end workflow.

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
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans