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 Percentage with different entity fields

(0) ShareShare
ReportReport
Posted on by

Hi,

i have

entity A with field a(currency)

entity B with field b(decimal)

entity c with field c(currency)

i want to calculate percentage in c= a*b/100

store value in field C

can help me 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mr Ramzy GHRIBI Profile Picture
    345 on at

    Hi,

    You need to create a plugin or call the web Api  using Javascript .

    Not possible with a workflow .

  • Community Member Profile Picture
    on at

    Thank you..Ramzi

    can u help me how to query the two different field values from two entitys

  • sandeepstw Profile Picture
    4,601 on at

    Hi,

    You can use calculate field www.encorebusiness.com/.../dynamics-crm-calculated-fields. If it does not helps. You can use CRM workflow/business rule which run on create or update of entities and calculate value based on conditions.

    I would like to know your requirement in detail and relationship between entities.

  • Community Member Profile Picture
    on at

    Hi Sandeep ,Thank you for reply,

    i am not able call the different entity field values in calculated fields

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Chaitu,

    The first thing I want to point is that its hard to store a value in the same field you are retrieving a value from. I would definitely suggest created another field alongside field C to ensure no looping effects are experienced with whichever solution you undertake. (i.e. trigger an OnChange event on field C, which will trigger again after the calculation is triggered, and again and again etc.)

    That being said, as you've stated, calculated fields only work on off the data that is stored on the entity itself, it will not be able to pull data from associated records. The best solution is the one suggested by Ramzi Ghribi through a plugin or Javascript.

    It is however possible to run the calculation from a single workflow that has the following conditions:

    • Field A and Field B must exist on Entity C to store Field A's and B's data. A duplicate field C must be set to hold the field C's current value. The field list would then be: Field A, Field B, Field C, Duplicate Field C.
    • Condition --> Entity A, Entity B and Field C must contain data, otherwise set Field A and Field B to "0"
    • Trigger --> OnUpdate of Entity A lookup OR OnUpdate of Entity B lookup OR OnUpdate of Field C, run the workflow
    • Step --> Update Entity C's field A and field B with the data from both lookup records.

    Then add a business rule in place to conduct the calculations (Set its scope to entity to ensure its done even in the background). The business rule must conduct the following:

    1. update the duplicate field C's value with the calculation; FieldA*FieldB

    2. set the current field C's value to the duplicate field C's value/100 and you should be good to go.

    That is a solution that does not require any dev and can be updated by either the customer or yourself with little disruption to the current records.

    If you are able to create a plugin, then use the following fetch structure seen on my blog (www.ec.co.za/.../dynamics-crm-plugins-the-basics) to build the fetch for Entity A and Entity B and conduct the calculation:

    if (EntityAEntity != null)
    {
    //EntityA
    String fetchEntityA = String.Format(@"", EntityARef.Id.ToString());

    EntityCollection EntityAresults = service.RetrieveMultiple(new FetchExpression(fetchEntityA));

    if (EntityAresults.Entities.Count == 1)
    {
    entityC["fieldaschema"] = new Money(FieldARef);

    service.Update(entityC);
    }
    }

    if (EntityB != null)
    {
    //EntityB
    String fetchEntityB = String.Format(@"", EntityBRef.Id.ToString());

    EntityCollection EntityBresults = service.RetrieveMultiple(new FetchExpression(fetchEntityB));

    if (EntityBresults.Entities.Count == 1)
    {
    entityC["fieldbschema"] = new Money(FieldARef);

    service.Update(entityC);
    }
    }

    Decimal FieldA = EntityCRef.Attributes.Contains("fieldaschema") ? ((Money)EntityCRef["fieldaschema"]).Value : 0;
    Decimal FieldB = EntityCRef.Attributes.Contains("fieldbschema") ? ((Decimal)EntityCRef["fieldbschema"]).Value : 0;

    decimal calculation = (FieldA * FieldB) / 100;

    entityC["fieldC"] = new Money(calculation);

    Obviously it's hard to determine any of the values outside of the initial requirement.

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Barry..

    Thank you so much for the response.Its working.

  • Michael Ual Profile Picture
    on at

    You can actually use other related entity fields in calculated fields by identifying the lookup field first.  In the example below, I have created a sample calculated text field on the case entity, and show how to retrieve field values on the related contact record:

    Sample-Calculated-Field.png

    Using calculated fields is likely the preferred method of doing this.

  • Community Member Profile Picture
    on at

    Hi Michael,

    You are 100% correct, I forgot that was available... apologies!

    community.dynamics.com/.../accessing-related-entities-fields-in-calculated-fields-formulas-in-microsoft-dynamics-crm-2015

  • mrutyunjai Profile Picture
    35 on at

    Hi chaitu, can you please provide full solution i am facing same issue.

  • mrutyunjai Profile Picture
    35 on at

    Hi Chaitu can you please give full solution i am facing the same issue

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