locked
Total time field in new Entity : CRM 2011 RRS feed

  • Question

  • I created a new Entity Called Project which contains a new field called Total Project Time and add a Task Entity as a grid into this project entity.

    Whenever a new task is associated to this project (when the project is set in the regarding field of the task) I want to sum up all the duration(Min) of each task associated to this project and put the total sum in the project Entity’s Total Duration field  

    How can I do this ... any idea or code?

    Thanks,

    Friday, September 23, 2011 11:03 PM

Answers

  • Hi,

    Find below the solution using workflow simplest approch:

    1. Create new workflow for Task Entity, it will trigger on Task Create or Regarding field value changed

    2. Add step, Check Condition              Project (Regarding)                  Equals                  Project          Contains Data       

    3. Add Step Update Record, in entity list choose Project , click on Set Properties button , In Operator select Increment by, in Field select Task Duration and and click Add

    4. Save and Activate workflow

    * The above workflow will not work in case of Updating Task duration because in Workflow you will always get the changed value and for sum claculation you need to first decrement the sum value

    You can also develop a plugin that will register on Task entity Create and Update events, the plugin will check if Task[regardingobjectid] is Project then it will retrieve Service.Retrieve("new_project",entityid) the project entity and update the Sum value, decrement older value and add new vlaue (or reclaculate value by summing up all related child records via FetchXml: http://msdn.microsoft.com/en-us/library/gg309565.aspx ) of the project via webservice Service.Update (projectentity) method.

    For plugin development you may refer: http://msdn.microsoft.com/en-us/library/gg695782.aspx


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, September 24, 2011 7:51 AM

All replies

  • Hi,

    Find below the solution using workflow simplest approch:

    1. Create new workflow for Task Entity, it will trigger on Task Create or Regarding field value changed

    2. Add step, Check Condition              Project (Regarding)                  Equals                  Project          Contains Data       

    3. Add Step Update Record, in entity list choose Project , click on Set Properties button , In Operator select Increment by, in Field select Task Duration and and click Add

    4. Save and Activate workflow

    * The above workflow will not work in case of Updating Task duration because in Workflow you will always get the changed value and for sum claculation you need to first decrement the sum value

    You can also develop a plugin that will register on Task entity Create and Update events, the plugin will check if Task[regardingobjectid] is Project then it will retrieve Service.Retrieve("new_project",entityid) the project entity and update the Sum value, decrement older value and add new vlaue (or reclaculate value by summing up all related child records via FetchXml: http://msdn.microsoft.com/en-us/library/gg309565.aspx ) of the project via webservice Service.Update (projectentity) method.

    For plugin development you may refer: http://msdn.microsoft.com/en-us/library/gg695782.aspx


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, September 24, 2011 7:51 AM
  • The best possible solution is to create a plugin and register it on create, update and setstate/set dynamic state.

    This way the value will be always upto date, The other solution is to display the sum total of grid rows on on the project entity.

    You can save this to if you want. here is one of the forum i answered about working with the grid data

    http://social.microsoft.com/Forums/en-US/crm/thread/34c1f094-6690-4e4a-97e5-0947d182f092/#146d0bef-04c3-4316-acf4-f43e876156a0

    I hope this helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Saturday, September 24, 2011 1:25 PM
    Saturday, September 24, 2011 1:25 PM