none
Sample C# plugin to update a different entity upon save

    Question

  • Can some one link me a page or give me a sample (including plugin registration steps) to create a C# plugin to do the following:
    When I save Entity1 I need to update Entity2
    Entity2 with have a lookup with Entity1 in it.

    If the sample could include both a text and lookup update that woulld be great.  Something simple just to get me going!!!

    THANK YOU!!!!!
    Withers
    Tuesday, November 17, 2009 3:58 PM

Answers

  • Hi, Withers.

    There are a lot of samples in Internet. You can use search engines like this ...

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, November 17, 2009 4:12 PM
  • So, basically you're looking to update children belonging to a parent.  In that case, what you'll want to do is:

    1.) Use QueryByAttribute to retrieve all Entity2 records with a value of Entity1.Entity1id in their parental reference field--note: you must specify the return of Entity2.Entity2id with the ColumnSet for that query, otherwise you will not be able to perform Update calls on those entities.
    2.) Then, loop through each Entity2 in the BusinessEntitiesCollection that's returned by the query, and add/replace the CrmLookupProperty and StringProperty entries in the Properties collection with the values you want to set.
    3.) Finally, call (inside the loop) an Update on the Entity2 record.


    Dave Berry
    Wednesday, November 18, 2009 1:47 AM

All replies

  • Hi, Withers.

    There are a lot of samples in Internet. You can use search engines like this ...

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, November 17, 2009 4:12 PM
  • I was hoping for a plugin sample for my exact scenario.  I am capable of searching google, ad have done so before posting.
    Withers
    Tuesday, November 17, 2009 5:44 PM
  • So, basically you're looking to update children belonging to a parent.  In that case, what you'll want to do is:

    1.) Use QueryByAttribute to retrieve all Entity2 records with a value of Entity1.Entity1id in their parental reference field--note: you must specify the return of Entity2.Entity2id with the ColumnSet for that query, otherwise you will not be able to perform Update calls on those entities.
    2.) Then, loop through each Entity2 in the BusinessEntitiesCollection that's returned by the query, and add/replace the CrmLookupProperty and StringProperty entries in the Properties collection with the values you want to set.
    3.) Finally, call (inside the loop) an Update on the Entity2 record.


    Dave Berry
    Wednesday, November 18, 2009 1:47 AM