Hi all.
I was playing around trying to add products to a quote with a workflow. I have basically copied a workflow i use in the pricelists and tried to modify it to work. Not quite sure what i'm missing so any help would be great. My current code is below. I get the sense i'm not correctly calling the quotedetail right to add the products. I idea is that in the quote entity i will have option boxes yes/no to add various groups of product to the quotes to speed up the creation.
public class Quoteproducts : CodeActivity
{
protected override void Execute(CodeActivityContext executionContext)
{
//Create the tracing service
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
//Create the context
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Create a column set to define which attributes should be retrieved.
ColumnSet attributes = new ColumnSet(true);
Entity currentPriceLevelEntity = new Entity("quote");
currentPriceLevelEntity = service.Retrieve("quote", CurrentQuote.Get<EntityReference>(executionContext).Id, attributes);
// Create New Price List
Entity newPriceLevel = new Entity("quote");
//newPriceLevel.Id = Guid.Parse(quotedetailId.Get<string>(executionContext));
// newPriceLevel["name"] = NewPriceListName.Get<string>(executionContext);
// newPriceLevel["sb_fpaid"] = Contractor.Get<string>(executionContext);
// newPriceLevel["sb_manholerun"] = manholerun.Get<int>(executionContext);
// newPriceLevel["transactioncurrencyid"] = currentPriceLevelEntity["transactioncurrencyid"];
service.Update(newPriceLevel);
newPriceLevel["MH900"] = MH900.Get<string>(executionContext);
// Get current product price level
QueryExpression productPriceLevelExpression = new QueryExpression("quotedetail");
FilterExpression productPriceLevelFilterExpression = new FilterExpression();
productPriceLevelFilterExpression.Conditions.Add(new ConditionExpression("quoteid", ConditionOperator.Equal, currentPriceLevelEntity["quoteid"]));
productPriceLevelExpression.ColumnSet = new ColumnSet(true);
productPriceLevelExpression.Criteria = productPriceLevelFilterExpression;
EntityCollection productPriceLevelList = service.RetrieveMultiple(productPriceLevelExpression);
// Create new product price level records
for (int index = 0; productPriceLevelList.Entities != null && index < productPriceLevelList.Entities.Count; index++)
{
Entity newProductPriceLevelEntity = new Entity("quotedetail");
// newProductPriceLevelEntity["pricelevelid"] = new EntityReference("pricelevel", newPriceLevel.Id);
// newProductPriceLevelEntity["productid"] = productPriceLevelList.Entities[index]["productid"];
newProductPriceLevelEntity["productnumber"] = "F0900 TAG VMHS F";
Guid guid = new Guid();
newProductPriceLevelEntity.Id = guid;
service.Create(newProductPriceLevelEntity);
}
}
private void mbox()
{
throw new NotImplementedException();
}
//Define the properties
[RequiredArgument]
[Input("Current Quote")]
//[ReferenceTarget("quote")]
public InArgument<string> CurrentQuote { get; set; }
[Input("MH900 : MH900")]
public InArgument<string> MH900 { get; set; }
Regards
Dan