locked
C# plugin - on Update: Get Quote Id from Quote Product RRS feed

  • Question

  • I am trying to retrieve a Quote Product's (QuoteItem) related QuoteId.  This is part of a c# plugin.  This event must be triggered for the Create and also for the Update of the QuoteItem entity.  It works fine for the Create, but on the Update I get an Error "Object not set to an Entity Reference".

    The part that gives me problems is the following:

     var QuoteEntityReferenceValue = QuoteProduct.GetAttributeValue<EntityReference>("quoteid");
                            ColumnSet p_attributes = new ColumnSet(new string[] { "pricelevelid"});
                            Entity Quote = _orgService.Retrieve("quote", QuoteEntityReferenceValue.Id, p_attributes);

     

    Christo Vermeulen

    Friday, June 20, 2014 8:18 AM

Answers

  • My guess is that QuoteProduct is a reference to the Target InputParameter. In an update message, this only contains attributes that were modified by the update, so quoteid won't be present. Use an EntityImage (Pre or Post will do in this scenario) to get the quoteid


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, June 20, 2014 9:06 AM
    Moderator

All replies

  • My guess is that QuoteProduct is a reference to the Target InputParameter. In an update message, this only contains attributes that were modified by the update, so quoteid won't be present. Use an EntityImage (Pre or Post will do in this scenario) to get the quoteid


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, June 20, 2014 9:06 AM
    Moderator
  • Hi,

    Plugin is register on QuoteItem right?

    Try to Use Entity Class:

     public void Execute(IServiceProvider serviceProvider)
    		{
            
                ITracingService tracingService =
                    (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
              
                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
               
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                {
                
                    Entity quoteItem = (Entity)context.InputParameters["Target"];
    				
    				if(quoteItem.attributes.contains("quoteid") && quoteItem["quoteid"] != null) //you just have this when is dirty
    				{
    					EntityReference  quoteid = (EntityReference)quoteItem["quoteid"];
    					
    					ColumnSet p_attributes = new ColumnSet(new string[] { "pricelevelid"});
                        Entity Quote = _orgService.Retrieve("quote", quoteid.Id, p_attributes)
    				}
    
                    
                }
    			
    		}

    Kind regards

    Friday, June 20, 2014 2:50 PM
  • Got the Image sorted out.  No it is working.  Thank you for the answer

    Christo Vermeulen

    Monday, June 23, 2014 6:41 AM