Hi all
I have some code that i currently use to create price list items as detailed below.
The way i'm trying to get it working as full overview is when a new price list is created if the user requires prices for a certain group of products they can fill in a few fields within the pricelist and then click the generate button. In the first instance the button runs a workflow then checks if a field(Flag) is set to 1 or not if the field is empty it runs the create plugin which adds all the products based on a default price list and while it's adding the products it works out the prices based on the users inputs. In the second instance where the user would like to update the prices the field(flag) is set to 1 so it runs the update plugin.
My question is how do i get the below code to work on the current pricelist instead of trying to get the data from the default price list
//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("pricelevel");
currentPriceLevelEntity = service.Retrieve("pricelevel", CurrentPriceList.Get<EntityReference>(executionContext).Id, attributes);
// Create New Price List
Entity newPriceLevel = new Entity("pricelevel");
newPriceLevel.Id = Guid.Parse(PriceListId.Get<string>(executionContext));
// newPriceLevel["name"] = NewPriceListName.Get<string>(executionContext);
// newPriceLevel["sb_fpaid"] = Contractor.Get<string>(executionContext);
// newPriceLevel["sb_merchant"] = Merchant.Get<string>(executionContext);
// newPriceLevel["transactioncurrencyid"] = currentPriceLevelEntity["transactioncurrencyid"];
service.Update(newPriceLevel);
newPriceLevel["Price900"] = ManholePrice900.Get<string>(executionContext);
newPriceLevel["Price1050"] = ManholePrice1050.Get<string>(executionContext);
newPriceLevel["Price1200"] = ManholePrice1200.Get<string>(executionContext);
newPriceLevel["Price1350"] = ManholePrice1350.Get<string>(executionContext);
newPriceLevel["Price1500"] = ManholePrice1500.Get<string>(executionContext);
newPriceLevel["Price1800"] = ManholePrice1800.Get<string>(executionContext);
newPriceLevel["Price2100"] = ManholePrice2100.Get<string>(executionContext);
newPriceLevel["Price2400"] = ManholePrice2400.Get<string>(executionContext);
newPriceLevel["Price2700"] = ManholePrice2700.Get<string>(executionContext);
newPriceLevel["Price3000"] = ManholePrice3000.Get<string>(executionContext);
newPriceLevel["StepPriceVal"] = StepsPrice.Get<string>(executionContext);
newPriceLevel["NoStepVal"] = NoStep.Get<string>(executionContext);
newPriceLevel["SoakAwayVal"] = Soakaway.Get<string>(executionContext);
decimal costamount;
decimal price900int = Convert.ToDecimal(newPriceLevel["Price900"]);
decimal price1050int = Convert.ToDecimal(newPriceLevel["Price1050"]);
decimal price1200int = Convert.ToDecimal(newPriceLevel["Price1200"]);
decimal price1350int = Convert.ToDecimal(newPriceLevel["Price1350"]);
decimal price1500int = Convert.ToDecimal(newPriceLevel["Price1500"]);
decimal price1800int = Convert.ToDecimal(newPriceLevel["Price1800"]);
decimal price2100int = Convert.ToDecimal(newPriceLevel["Price2100"]);
decimal price2400int = Convert.ToDecimal(newPriceLevel["Price2400"]);
decimal price2700int = Convert.ToDecimal(newPriceLevel["Price2700"]);
decimal price3000int = Convert.ToDecimal(newPriceLevel["Price3000"]);
decimal steppriceint = Convert.ToDecimal(newPriceLevel["StepPriceVal"]);
decimal nostepint = Convert.ToDecimal(newPriceLevel["NoStepVal"]);
decimal Soakawayint = Convert.ToDecimal(newPriceLevel["SoakAwayVal"]);
// Get current product price level
QueryExpression productPriceLevelExpression = new QueryExpression("productpricelevel");
FilterExpression productPriceLevelFilterExpression = new FilterExpression();
productPriceLevelFilterExpression.Conditions.Add(new ConditionExpression("pricelevelid", ConditionOperator.Equal, currentPriceLevelEntity["pricelevelid"]));
productPriceLevelExpression.ColumnSet = new ColumnSet(true);
productPriceLevelExpression.Criteria = productPriceLevelFilterExpression;
EntityCollection productPriceLevelList = service.RetrieveMultiple(productPriceLevelExpression);
// Update new product price level records
for (int index = 0; productPriceLevelList.Entities != null && index < productPriceLevelList.Entities.Count; index++)
{
Entity newProductPriceLevelEntity = new Entity("productpricelevel");
newProductPriceLevelEntity["pricelevelid"] = new EntityReference("pricelevel", newPriceLevel.Id);
newProductPriceLevelEntity["productid"] = productPriceLevelList.Entities[index]["productid"];
newProductPriceLevelEntity["productnumber"] = productPriceLevelList.Entities[index]["productnumber"];
newProductPriceLevelEntity["uomid"] = productPriceLevelList.Entities[index]["uomid"];
string prodidse = Convert.ToString(productPriceLevelList.Entities[index]["productnumber"]);
newProductPriceLevelEntity.Id = productPriceLevelList.Entities[index].Id;
//900 ring price makeup
if (prodidse == "F0900 TAG VMHS F")
{
costamount = price900int;
goto endt;
}
else if (prodidse == "F0900 TAG VMHS T")
{
costamount = price900int / 4 * 3;
goto endt;
}
else if (prodidse == "F0900 TAG VMHS H")
{
costamount = price900int / 4 * 2 / 100 * 150;
goto endt;
}
else if (prodidse == "F0900 TAG VMHS Q")
{
costamount = price900int / 4 / 100 * 200;
goto endt;
}
else if (prodidse == "F3000 TAG SOAKRTR")
{
costamount = price3000int / 4 / 100 * 200 + (Soakawayint * 27) + (steppriceint * 3);
goto endt;
}
else if (prodidse == "F3000 TAG SOAKRHR")
{
costamount = price3000int / 4 / 100 * 200 + (Soakawayint * 18) + (steppriceint * 2);
goto endt;
}
else
{
costamount = 0;
;
}
endt:
productPriceLevelList.Entities[index]["amount"] = new Money(costamount);
service.Update(productPriceLevelList.Entities[index]);
}
Kind Regards
Dan