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)

Dynamics 365 calculated field value to another field within same entity

(0) ShareShare
ReportReport
Posted on by 125

Good morning, 

I was wondering if there is a way to move the value of a calculated field to another field type that is not calculated. I tried business rule and workflows and they do not work with calculated fields. I am sure there is a way to do this, I just have not found this. 

Thank you, 

Joseph

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    You can do that with simple Javascript code.

    As you know (I think) calculated fields are virtual fields so their data not saved on database. As your calculation formula/rules their data re-calculate every form onload event. 

    You can use this javascript code on form onload event or calculated field's onchange event.

    function copyData() {
        var calculatedFieldValue = Xrm.Page.getAttribute("YOUR_CALCULATED_FIELD_NAME").getValue();
        Xrm.Page.getAttribute("YOUR_OTHER_FIELD_NAME").setValue(calculatedFieldValue);
    }


  • Joseph Melillo Profile Picture
    125 on at

    Hi Emre,

    Thank you for your advice. I have created a calculated field that would calculated "Finance Request," Problem is that we already have old records using a field called "Finance Request amount" (the value is not the same since they typed it manually). When I publish the changes their old history would not be accurate.

    is there way to have the script say:

    If calculated field is modified or created update Finance Request?

    Thank you,

    Joseph Melillo

  • Suggested answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    "CalculatedFields" are virtual fields and you can not trigger any plugin / workflow on their change (please look at https://technet.microsoft.com/en-us/library/dn832103.aspx#Considerations for more information), however on clientside you can use javascript on field onChange event (you can use my sample javascript code).

    CalculatedFields' calculation doing on data retrieve process (Retrieve - RetrieveMultiple), so field calculates his value when record form loading or Retrieve / RetrieveMultiple methods running on SDK side.

    I'm not sure but maybe you can update NULL or 0(zero) your old field (Finance Request amount) or you can remove directly from form and entity. Your wrong calculated (manually typed) datas will removed on database and then if you re-calculate value use "Advanced Find" or SDK RetrieveMultiple (with QueryExpression) to retrieve your all existing data (but I think you don't need that, because you field re-calculate everytime when you retrieve it, so you always get correct data -if you did correct calculation formula :) -)

  • Joseph Melillo Profile Picture
    125 on at

    Hi Emre,

    Thank you for your reply. I inserted an image of what I am trying to accomplish. I apologize if I am not understanding, I am new to Javascripts. I normally do things out of the box, but cannot figure out a better way.

    cal-to-regular-field.PNG

    I have setup the calculation field and formula correctly. I would like to keep the Fiance Request Field since it has our history. Currently, When they open an old opportunity (after the changes have been made) you will notice that the Finance Request Calc field is blink. This will only calc after all the required information is added (I want to keep it this way since I have added 1 extra field and want the information filled out). 

    Going forward, I would like the JaveScript to say: when value is added to the finance request cal, move the value of the calculated field to Finance Request. 

    I believe the current script you provided me would over ride the current information, am I wrong>?? 

    Thank you so much for your help. 

    Joseph

  • Suggested answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    If your formula is correct and all related fields have value your calculated field will be filled when you retrieve your record (for ex. on form onload event).

    If you copy/move data from calculated field to your other field (in this example "Finance Request" field) your current data will be replaced by your calculated field's value.

    If you need save/report old values you should enable "Audit" (please look at https://crmbook.powerobjects.com/basics/data-management-in-microsoft-dynamics-crm/auditing-in-microsoft-dynamics-crm/ for more information) or maybe create a 1:N related entity solution.

  • Joseph Melillo Profile Picture
    125 on at

    Hi, 

    I have added the script but nothing happens. 

    function copyData() {
    var calculatedFieldValue = Xrm.Page.getAttribute("new_financerequestcalc").getValue();
    Xrm.Page.getAttribute("new_financerequest1").setValue(calculatedFieldValue);
    }

    3343.value.PNG

    what did I do wrong?? When I enter new values, the calculated field changes but the other field does not. Not even at new. 

    Thank you, 

    Joseph

  • Verified answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    If your calculated field is "new_financerequestcalc", you should run this javascript on "new_financerequestcalc" onchange event.

    Your calculation formula runs form's "onsave" and "onload" events, so if you change your formula related fields and save your record, calculated data filled with new value and your javascript function will run when data changed and copy your new calculated value to other field.

  • Joseph Melillo Profile Picture
    125 on at

    Hi Emre,

    I got this to work on the Form. As I was testing this out, I ran into another problem. When user create this in the "Quick Create Form" this does not work and after I fill out the information (required fields) the scrip does not run. Anyway to have this also working on the quick create form?

    Thank you so much for this, big big help.

    Joseph

  • Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    In my experience you can not add calculated fields to quick create forms.

    maybe you can disable quick create option for your entity

  • Joseph Melillo Profile Picture
    125 on at

    That is what I am thinking.

    Question: The code you provided me, can it be used for other types of fields if I change the code Var CalculatedFieldValue to a different type??

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