locked
Run WF on an entity after attaching records to it RRS feed

  • Question

  • I am facing the below scenario.  I have 2 entities related to each other by 1 - M Relation:-

    * Months Medicines, Fields: Total per month

    * Days Medicines, Fields: Total per day

    - 'Months Medicines' contains a grid of type 'Days Medicines'; user may attach multiple 'Days Medicines' records to it.

    - Whenever any record from 'Days Medicines' is attached to 'Months Medicines', I want to add the 'total per day' from 'Days Medicines' onto 'Total per month' field in 'Months Medicines'.

    - I've implemented that using a custom WF at which i send the 'Total per month' as a parameter to add on it the 'Total per day' and save the new value.

    My problem is that if i attached 4 records, the WF will run 4 times at the same time with the same input value. Hence, the final value will be wrongly calculated (it will always add one record only on the value sent). I tried retrieving the value inside the code but have the same result. Is there any way to make these WFs run sequential??

    Sunday, March 2, 2014 8:11 PM

Answers

  • Thank you for your reply but i think that plugins won't work correctly as well. we've implemented this part by locking the workflow code.
    • Marked as answer by Soha Nasr Sunday, June 12, 2016 10:03 AM
    Saturday, March 8, 2014 12:55 AM

All replies

  • For your scenario, I recommend using synchronous plugin or real-time workflows (if yours is CRM 2013) since there's no way you can control the child workflow activities to run sequentially.
    • Proposed as answer by HIMBAPModerator Monday, March 3, 2014 5:46 AM
    • Unproposed as answer by Soha Nasr Tuesday, June 14, 2016 8:37 AM
    Monday, March 3, 2014 2:03 AM
  • Thank you for your reply but i think that plugins won't work correctly as well. we've implemented this part by locking the workflow code.
    • Marked as answer by Soha Nasr Sunday, June 12, 2016 10:03 AM
    Saturday, March 8, 2014 12:55 AM
  • It should work correctly unless multiple records of "Days Medicines" are attached concurrently.

    Anyway, update your plugin/custom workflow logic to recalculate the value by retrieving all "Total Per Day" values from related child  "Days Medicines" records and update in "Total Per Month" instead of adding/subtracting the current value.

    That should solve your issue.

    Monday, March 10, 2014 3:10 PM
  • Exactly, the point is that the records are attached concurrently.

    When clicking on "Add existing items" to the grid and checking 5 records for example, all of them are attached concurrently. Hence, the workflow is called for them at the same time at which the other records are not yet attached which makes the "Total Per Day" always wrongly calculated.

    Again, thank you for you help :)

    Tuesday, March 18, 2014 7:16 PM
  • Then, update the logic of your plugin/custom workflow according to my 2nd suggestion in the previous post.  

    Anyway, update your plugin/custom workflow logic to recalculate the value by retrieving all "Total Per Day" values from related child  "Days Medicines" records and update in "Total Per Month" instead of adding/subtracting the current value.

    Then, the last firing should fetch all the related child "Days Medicines" records and update the correct value.

    Wednesday, March 19, 2014 2:53 AM
  • I)

    1. Make months medicines as required field.

    2. create plugin on create/update of days medicine

    In plugin get months medicine via fetchxml then update the medicines.

    II)

    register plugin on Associate

    primary entity: medincine,

    context.InputParameters.Contains(“Target”) && context.InputParameters["Target"] is EntityReference

    secondary entity: days

    context.InputParameters.Contains(“RelatedEntities”) && context.InputParameters["RelatedEntities"] is EntityReferenceCollection

    See for more help

    https://rajeevpentyala.wordpress.com/category/crm/crm-2011/plug-ins/

    section :Associate/Disassociate plugin messages in CRM


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Mr. Santosh Bhagat Wednesday, March 19, 2014 5:56 AM
    • Unproposed as answer by Soha Nasr Tuesday, June 14, 2016 8:36 AM
    Wednesday, March 19, 2014 5:55 AM
  • Sorry :( but unfortunately this will not help either since the calculations will run at the same time and will override each other. The only thing that worked for me is locking the code.

    Thanks a lot for your help

    Sunday, June 12, 2016 10:02 AM