I am using following code snippet to set the Invoice ID of Invoices in plugin pre-operation. But I am unable to do so. I want to seek your kind suggestion to set the value.
Update
QueryExpression qe = new QueryExpression
{
EntityName = "invoice",
ColumnSet = new ColumnSet("salesorderid", "invoicenumber"),
Criteria = new FilterExpression
{
Conditions = {
new ConditionExpression("salesorderid",ConditionOperator.Equal,orderId)
}
}
};
EntityCollection ec = service.RetrieveMultiple(qe);
if (ec.Entities.Count == 0)
{
string orderName = generateInvoiceID(service, orderId);
foreach (Entity id in ec.Entities)
{
id.Attributes["invoicenumber"] = Convert.ToInt32(orderName) + 01;
}
}
Looking at the snippet looks like you have the plugin registered on "SalesOrder" entity and you are trying to update invoice entity, so it does not matter if it is a pre-op or a post-op, you would need to explicitly call IOrganizationService.Update
var qe = new QueryExpression
{
EntityName = "invoice",
ColumnSet = new ColumnSet("salesorderid", "invoicenumber"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("salesorderid", ConditionOperator.Equal, orderId)
}
}
};
var ec = service.RetrieveMultiple(qe);
var orderName = generateInvoiceID(service, orderId);
foreach (var entity in ec.Entities)
{
var invoice = new Entity("invoice") { Id = entity.Id };
invoice.Attributes.Add("invoicenumber", Convert.ToInt32(orderName) + 01);
service.Update(invoice); //call the update method.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.