locked
Add items to quotedetails RRS feed

  • Question

  • I am trying to write a new line to a quote in Dynamics CRM, I have queried for the existing quotes Id and am trying to assign that but it fails saying "NullreferenceException was unhandled Object Reference not set to an instance of the object"

    QuoteDetail quotedetail = new QuoteDetail();
              
    
                quotedetail.QuoteId.Id = quoteId;
                quotedetail.ProductId.Id = ProdId;
                quotedetail.sp_SellingUnitId.Id = UnitId;
                quotedetail.TransactionCurrencyId.Id = TCId;
                quotedetail.OwnerId.Id = OwnerId;
                quotedetail.Quantity = 54;
    
                _quoteDetailId = _serviceProxy.Create(quotedetail);

    Any help would be appreciated.

    Matt

    Friday, October 9, 2015 2:51 PM

Answers

All replies

  • Hello,

    Tru to use following code:

    QuoteDetail quotedetail = new QuoteDetail();
              
    quotedetail.QuoteId = new EntityReference("quote", quoteId);
    quotedetail.ProductId = new EntityReference("product", ProdId);
    quotedetail.sp_SellingUnitId = new EntityReference("Put schema name of this referenced entity here", UnitId);
    //quotedetail.TransactionCurrencyId.Id = TCId;//you don't need this fields in this case
    //quotedetail.OwnerId.Id = OwnerId;//you don't need this fields in this case
    quotedetail.Quantity = 54;
    
    _quoteDetailId = _serviceProxy.Create(quotedetail);


    Dynamics CRM MVP
    My blog

    Friday, October 9, 2015 4:27 PM
    Moderator
  • Ok I have updated it to this:

                QuoteDetail quotedetail = new QuoteDetail();
    
                quotedetail.QuoteId = new EntityReference("quote", quoteId);
                quotedetail.ProductId = new EntityReference("product", ProdId);
    
    
                //quotedetail.sp_SellingProductId = new EntityReference("sp_SellingProductId", ProdId);
    
    
    
                //quotedetail.OwnerId.Id = new EntityReference("ownerid", OwnerId);
                //quotedetail.TransactionCurrencyId.Id = new EntityReference("transactioncurrencyid", TCId);
                
                quotedetail.Quantity = 54;
    
    
    
    
                    _quoteDetailId = _serviceProxy.Create(quotedetail);

    When I get to the line "_quoteDetailId = _serviceProxy.Create(quotedetail);" it errors with "FaultException`1 was unhandled" "The unit id is missing"

    I assume this is telling me I need to create this as its a required field?

    Matt

    Monday, October 12, 2015 11:45 AM
  • Hello,

    You need to add following line to your code:

    quotedetail.UoMId = new EntityReference("uom", Guid.Parse("Identifier of UoM record here"));


    Dynamics CRM MVP
    My blog

    Monday, October 12, 2015 12:41 PM
    Moderator
  • I Think that you need a unit set on the Product considering that you are referencing the Product. You're not allowed to set a unit on a quotedetail if you are using an existing Product AFAIK.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Thursday, October 22, 2015 1:03 PM
  • As this is an interface to CRM I am wanting to do the following:

                quotedetail.CreatedBy.Id = userId;
                quotedetail.ModifiedBy.Id = userId;
                quotedetail.ModifiedOnBehalfBy.Id = userId;
                quotedetail.TransactionCurrencyId.Id = TCId; 
                quotedetail.OwnerId.Id = OwnerId;

    If I change them to EntityReference it is saying that the fields cannot be assigned to as they are readonly, is this right or am I doing something wrong?

    Matt 

    Tuesday, November 3, 2015 3:42 PM
  • Hi Matt,

    Just of the top of my head, you can't set createdby and modifiedby, the rest of them I think you can set.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    • Marked as answer by Matt_H_UK Wednesday, November 11, 2015 4:38 PM
    Tuesday, November 3, 2015 4:45 PM