Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin to do a roll up field in Dynamics CRM 2013

Posted on by 330

Unfortunately Dynamics CRM 2013 does not have a roll up field which perfectly suits my requirement.

So I  have a parent entity called Savings and a child entity called deposit.

So savings as many deposits.

On the deposit entity there is a currency field called amount deposited.

and on the savings entity there is a field called total amount deposited.

I need a plugin on update , delete or modify of the deposit amount field, it will roll up the deposit amount filed tied to the savings and update the field Total Amount deposited.

On the deposit entity the savings look up is a required field.

I just started learning plugins and have been able to fully understand the follow up plugin in the sample SDK and execute it myself.

will appreciate any help , already figured the plugin logic.

on the deposit entity anytime the change is made the code will do a look up to the savings then do a loop of the deposit amount associated the the savings and add it up, the loop  is my challenge

Regards.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    You can also use this tool to format fetch xml: arunpotti.wordpress.com/.../fetchxml-formatter-tool

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    community.dynamics.com/.../244962

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    Try following:

    var fetchxml = @"<fetch mapping='logical' version='1.0' distinct='false' output-format='xml-platform'>

               <entity name='plx_deposit'>

                <attribute name='plx_amount' alias='totalamount' aggregate='sum'/>

                <filter type='and'>

               <condition value='" + savingsID.ToString() + @"'  attribute='plx_savings' operator='eq' uitype='plx_production'  />

                </filter>

                </entity>

                </fetch>";

    Also

    Entity savings = new Entity("plx_savings", savingsID);

    would not create new record - it's just an instantiation of object. And the other things how you will use it. If you will call

    service.Create(savings) - that will try to create a new record

    but if you will call

    service.Update(savings) - that will try to create update an existing Savings record with savingsID record.

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    IT KEEPS GIVING A SYNTAX ERROR is this ok

    String fetchxml = @"<fetch mapping='logical' version='1.0' distinct='false' output-format='xml-platform'>

                <entity name='plx_deposit'>

                 <attribute name='plx_amount' alias='totalamount' aggregate='sum'/>

                 <filter type='and'>

                <condition value=" + "savingsID" + @"  attribute='plx_savings' operator='eq' uitype='plx_production'  />

                 </filter>

                 </entity>

                 </fetch>";

    But have added it now and no error will this work?

    also wont this create a new entity

    Entity savings = new Entity("plx_savings", savingsID);

    was thinking of

    ColumnSet orderCols = new ColumnSet(new String[] { "plx_totalamount" });

    Entity Savings = service.Retrieve("pls_savings", savingsID, orderCols);

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    Also what I saw in your code - in line <condition value=" + savingsID + "...

    it should contain additional quotes before/after doublequotes something like

    <condition value='" + savingsID + "'...

    otherwise your retrievemultiple call will fail.

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    Let me see if i made an effort

    Entity savings = service.Terieve("plx+savings", savingsID)

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    Add new before Entity like

    Entity savings = new Entity("plx_savings", savingsID);

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    0841.forum.PNG

    Thanks it still gives same error , nothing like Deposing so i used entity

    var savingsID = entity.GetAttributeValue<EntityReference>("plx_savings").Id;

    Entity savings = Entity ("pls_savings", savingsID);

    Entity is a type but used like a variable

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    It should be something like:

    var savingsID = Deposing.GetAttributeValue<EntityReference>("plx_savings").Id;

    Entity savings = Entity("plx_savings", savingsID);

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Plugin to do a roll up field in Dynamics CRM 2013

    Thanks this gave a error

    Entity savings = Entity("plx_savings", <savingsID>);

    Entity is a type but used like a variable

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans