-1

I'm using OrganizationServiceClient with CRM 2011, When I create an invoicedetail with a manualdiscountamount, the discount doesn't appear in the CRM website. Here's my code:

OrganizationServiceClient client = new OrganizationServiceClient("CustomBinding_IOrganizationService",new EndpointAddress(AuthenticationInfo.OrganizationServiceUrl))) {                client.ConfigureCrmOnlineBinding(AuthenticationInfo.OrganizationPolicy.IssuerUri);
client.Token = AuthenticationInfo.OrganizationToken;

Entity entityDetails =  = new Entity();
entityDetails.LogicalName = "invoicedetail";
entityDetails.Attributes = new AttributeCollection();
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "productid",
                                value =
                                    new EntityReference() {
                                        LogicalName = "product",
                                        Id = Guid.Parse("Some Product Id")
                                    }
                            });
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "uomid",
                                value =
                                    new EntityReference() {
                                        LogicalName = "uom",
                                        Id = Guid.Parse("33B75DB8-8771-4B5A-875F-810CC0732C0C")
                                    }
                            });
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "invoiceid",
                                value = new EntityReference() {LogicalName = "invoice", Id = Guid.Parse("Some Invoice Id")}
                            });
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "quantity",
                                value = 1
                            });
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "createdon",
                                value = DateTime.Now
                            });
entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "manualdiscountamount",
                                value = 15
                            });

invoiceDetailsId = client.Create(entityDetails);

What may be the problem here?

Keshava GN
  • 4,195
  • 2
  • 36
  • 47
Saied
  • 32
  • 3

1 Answers1

0

Try to use following code to add manualdiscountamount field:

entityDetails.Attributes.Add(new KeyValuePairOfstringanyType() {
                                key = "manualdiscountamount",
                                value = new Money(Convert.ToDecimal(15))
                            });

Because manualdiscountamount field is of Money type. Recheck following article

Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13