locked
entity relationship parent child question RRS feed

  • Question

  • Hi,

    I have two custom entities(parent and child  customentityparent, customentitychild)

    Customentityparent has the following fields

    {New_invoice <lookup for invoice>

    Invoicedetailguidtext*<text field that stores the guid of the invoice detail record>

    …}

    Customentitychild  has some text fields

    {attribute a, attribute b, attribute c are text fields, attribute d <lookup for invoice>}.

    Please note that there could be 100s of child for every parent record, but avg is about 10.

    I am looking for an efficient way to combine the text fields of each child record per parent (in a string)  after every create, update or delete action of child.  

    *finally I need to capture this combined string in invoice-detail entity. The combined text should be 

    a1+b1+c1 <next line> 

    a2+b2+c2 <next line> ...

    an+bn+cn 

     I am thinking of going with a custom ribbon element in the invoice detail entity – on click, that will call a plug-in to process all the child records. Is that feasible. Or is there a better way? Appreciate if anyone could advise   <on add/delete/update of child, I could use a plugin may be aschyn mode.. )

    Thursday, August 11, 2011 12:23 PM

Answers

  • Thursday, August 11, 2011 3:57 PM
  • Hi,


    You cannot use ribbon element to call plugin unless you update data into form and save for submission and if plugin is registered for Update event then it will only work and this approach will not work on child entity record creation and deletion.

    If you are looking for real-time solution then register plugin steps as below.
    I would suggest you the following:

    1. Write a method that will combine all entities text as per required by fetching all child entity records (Retrieve Multiple or LinQ will do the job)
    2. Register plugin steps for:
    a. Create Message on Post-Operation Asynchronous Execution (System will create a System Job for execution will take time like workflow execution)
    b. Update Message on Post-Operation Asynchronous Execution
    c. Delete Message on Pre-Operation, you cannot do it on Post-Operation because record will be deleted and you will be unable to retrieve parent entity Id. Recommend is to use Pre Operation Synchronous Execution


    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".
    • Marked as answer by CRM elite Sunday, August 14, 2011 1:56 PM
    Thursday, August 11, 2011 4:11 PM

All replies

  • Thursday, August 11, 2011 3:57 PM
  • Hi,


    You cannot use ribbon element to call plugin unless you update data into form and save for submission and if plugin is registered for Update event then it will only work and this approach will not work on child entity record creation and deletion.

    If you are looking for real-time solution then register plugin steps as below.
    I would suggest you the following:

    1. Write a method that will combine all entities text as per required by fetching all child entity records (Retrieve Multiple or LinQ will do the job)
    2. Register plugin steps for:
    a. Create Message on Post-Operation Asynchronous Execution (System will create a System Job for execution will take time like workflow execution)
    b. Update Message on Post-Operation Asynchronous Execution
    c. Delete Message on Pre-Operation, you cannot do it on Post-Operation because record will be deleted and you will be unable to retrieve parent entity Id. Recommend is to use Pre Operation Synchronous Execution


    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".
    • Marked as answer by CRM elite Sunday, August 14, 2011 1:56 PM
    Thursday, August 11, 2011 4:11 PM