Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calculate value of Calculated field by c# code

(0) ShareShare
ReportReport
Posted on by 515

Hello,

I need some custom logic to calculate value of calculated field, suppose, I have field1, field2 and field3. All of them are of whole number type, I have a Calculated filed named Result. I want calculate Result field like maximum(field1, field2, field3). I want to show maximum value out of this three field in Result field. I know this kind of calculation I can do by using JavaScript. but I want to do it by C# code (plugin or any other similar approach).

Is it possible to Calculate value this way? if yes can any one suggest me some document/article to develop such solution.

Thanks,

Ashish

*This post is locked for comments

  • Ashish Moradiya Profile Picture
    Ashish Moradiya 515 on at
    RE: Calculate value of Calculated field by c# code

    Very much correct, since I am calculating value in plugin of some field than it is regular field, calculated field doesn't makes any sense here.

    thanks!

  • Verified answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Calculate value of Calculated field by c# code

    Sure it is. Although, you'll probably need to make that field a regular field, not a calculated one (since you'll be calculating it in the plugin instead). There are lots of plugin examples.. this is what came up when I just searched quickly:

    community.dynamics.com/.../crm-2013-plugins-simple-update-plugin-redeploying-improving-and-updating

    msdn.microsoft.com/.../gg594416.aspx

  • Ashish Moradiya Profile Picture
    Ashish Moradiya 515 on at
    RE: Calculate value of Calculated field by c# code

    Hi,

    Thanks Alex for your answer, I can understand that I could use few if-else condition to achive my this requirement, but in some case I have very complex requirement that I want to do by c# code. My main question is that, is it possible to do so?

    Thanks,

    Ashish

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Calculate value of Calculated field by c# code

    Hi,

     you might define a calculated field, btw.. If it's just to calculate the maximum(that may include a few if-else conditions, but, in the end, you don't necessarily need a plugin for that):

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

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Calculate value of Calculated field by c# code

    You could calculate this in a plugin. The way I'd do this is a plugin on the update and create messages. I'm not sure if the calculated fields (field1 etc) are passed in the Target or EntityImages - if not you can use a Retrieve to get the current values, and do your calculation.

    For the Update plugin, it should run on a change to any of the source fields that the calculated fields are calculated from

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans