locked
CRM 4: Updating entity records and there childs using plugin RRS feed

  • Question

  • Hi all,

     

    here is the situation:

    I was trying to develop a plugin to trigger on the update event of a custom entity (let's call it entity A) to update related quotes and there child quote products

     

    I was doing this through the following steps:

    1 - retrieving quote IDs that are related to the updated A record in Guid array and then update records through a for loop

    2 - retrieving quotedetailid where quote id = <the quote id retrieved in step 1> in Guid array using a nested for lop inside the for loop at step 1 and then update records

     

    step 1 one is working correctly but for some reasons step 2 is not !!!

     

    there is no error messages or something like this but it's just not working

     

     

    could any body please help me on this ??

     

    thanks in advance..


    Monday, June 27, 2011 2:23 PM

Answers

All replies

  • Monday, June 27, 2011 2:55 PM
    Moderator
  • Dear Mahendar,

     

    that's really helpful, but I need to use it with Dynamice Entity class as there exist a cutom entity and custom fields in the quote and quote product entities

     

    thanks

    Monday, June 27, 2011 3:43 PM
  • yes you can use it with dynamic entity.


    Mahain : My Dynamics CRM Blog
    Monday, June 27, 2011 3:54 PM
    Moderator
  • There is a plugin that allows you to run a workflow on all child records.  We like it as it allows us to have more of a visual presence, aka workflow execution history.

    http://crm40distributewf.codeplex.com/

     

    Works great!


    David Withers
    Monday, June 27, 2011 4:03 PM
  • Dear David,

     

    Unfortunately I can't do it using a workflow, as there exist some calculated fields

    anyway thanks alot for your help :)

    Monday, June 27, 2011 4:06 PM
  • Dear Mahendar,

     

    I've retrieved all the quotedetail IDs in an array of type Guid

     

    now I need to update a money field in all Quote Item with a static value (let it be 2),

     

    so I've tried the following:

              RetrieveMultipleResponse quoteProductRetrieved = ( RetrieveMultipleResponse ) service . Execute ( quoteProductRetrieve );
    
              int productCount=quoteProductRetrieved.BusinessEntityCollection.BusinessEntities.Count();
    
              Guid [ ] quoteProductId = new Guid [ productCount ];
    
              for ( int j = 0 ; j < productCount ;j++ )
              {
                if ( RetrieveQuoteProduct . Properties . Contains ( "quotedetailid" ) )
    {
                  quoteProductId [ j ] = ( ( Key ) RetrieveQuoteProduct . Properties [ "quotedetailid" ] ) . Value;            
    
    DynamicEntity QuoteProductUpdate = new DynamicEntity ( );
    
                QuoteProductUpdate . Name = "quotedetail";
    
                ////Create a KeyProperty to hold the guid of the record to be updated
                KeyProperty QuoteProductGuid = new KeyProperty ( );
    
                QuoteProductGuid . Name = "quotedetailid";
    
                Key QuoteProductKey = new Key ( );
    
                QuoteProductKey . Value = new Guid ( quoteProductId [ i ] . ToString ( ) );
    
                QuoteProductGuid . Value = QuoteProductKey;
    
                QuoteProductUpdate . Properties . Add ( QuoteProductGuid );
    
                ////update value of sales policy fields in quote
                CrmMoneyPropertynew_field = new CrmMoneyProperty ( );
                financingFees . Name = "new_field";
                financingFees . Value = new CrmMoney ( );
                financingFees . Value . Value = 2; //(Decimal)tempBidBondFee;
    
                QuoteProductUpdate . Properties . Add ( financingFees );
                service . Update ( QuoteProductUpdate );
    }
    }
    

    but it's not working

     

    What I know is that the below statement:

     if ( RetrieveQuoteProduct . Properties . Contains ( "quotedetailid" ) )
    

    check that the quotedetailid is not null, please correct if I'm wrong, so I think that it cannot retrieve any quotedetailid for some reason

     

    please advise...

    Monday, June 27, 2011 4:41 PM
  • any suggestions ??
    Monday, June 27, 2011 7:10 PM
  • Dear Mahendar,

     

    the statement:

    ReadAllOrderLineItems(_SalesorderID); 
    

    what exactly does it return ??

     

    thanks in advance..

    Tuesday, June 28, 2011 8:28 AM
  • Dear Mostafa,

    ReadAllOrderLineItems(_SalesorderID); //I have written this function to fetch all order line items based on salesorder id.

    your code is not correct, I will suggest you to read post carefully.

     


    Mahain : My Dynamics CRM Blog
    Tuesday, June 28, 2011 9:33 AM
    Moderator
  • Dear Mahendar,

     

    I know that my code is not correct, If it is correct why would ask for help !!!

    I need help to correct it.

     

    Also I can read the comment, but I coudl not understand what does "fetch all order line items" mean ?? do you mena that you fetch the orderlineitems IDs or what !

     

    as a side note, I can not use this function without declaring it :)

     

    thanks alot for your help

    Tuesday, June 28, 2011 9:38 AM