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)

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

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    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

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    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

  • Ashish Moradiya Profile Picture
    515 on at

    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

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    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
    515 on at

    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!

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