Hi All
I'm trying to write a plugin to check if a product exist within a price list and if not add it. I have 900+ Price lists that i need to check.
The way new price list are created is that i have a plugin that basically copies a default price list and generates prices based on the user input. I thought about running this over the top of the existing price lists but obviously a single product out of 50 is already in the price list it brings back an error. Below is the first section of code i'm trying to base this plugin around
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_manholerun"] = manholerun.Get<int>(executionContext);
// newPriceLevel["transactioncurrencyid"] = currentPriceLevelEntity["transactioncurrencyid"];
service.Update(newPriceLevel);
newPriceLevel["cs900x600sq"] = cs900x600sqin.Get<string>(executionContext);
newPriceLevel["cs900x675sq"] = cs900x675sqin.Get<string>(executionContext);
decimal cs900x600sqint = Convert.ToDecimal(newPriceLevel["cs900x600sq"]);
decimal cs900x675sqint = Convert.ToDecimal(newPriceLevel["cs900x675sq"]);
// 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);
// Create 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(newProductPriceLevelEntity["productnumber"]);
Guid guid = new Guid();
newProductPriceLevelEntity.Id = guid;
decimal costamount = 0;
// cover slabs 900
if (prodidse == "F0900H VMCSS RHD")
{
costamount = cs900x600sqint;
goto endt;
}
else if (prodidse == "F0900I VMCSS RHD")
{
costamount = cs900x675sqint;
goto endt;
}
Any Ideas
Many Thanks
Dan
*This post is locked for comments
Hi Thank you for your comments
The current plugin add's about 550 products to each new price list this takes roughly 25 seconds to complete. The new plugin i'm trying to do would add as a maximum of 110 products so fingers crossed should be ok
Alex do you have any examples on how to check if the product exists and then add if not
Regards
Dan
Hi,
you might be able to work around the 2 minutes limitation and to simplify the plugin at the same time..
Create two plugins:
1. Sync or Async(both should work).. on whatever entity that tells you there is a new product:
When there is a product to add, update a field on the price list entity (new custom field). This is to trigger the second plugin.
2. Async plugin on the prices list, with that new custom field from #1 as a trigger
Check if the product is already in the pricelist for which the plugin is called (you'll need to figure out how to find out which product is being added.. so will have to store it somewhere in #1 so you could access it here). If the product is not there, add it
#1 plugin should probably complete in under 2 minutes for a simpel update
#2 plugin will run per price list, so should be fine as well
OR make it an external utility and schedule it somewhere.
Can't help you on the C# part, but I would be careful with the 2 minutes plugin timeout setting.
If your logic needs to browse a lot of records in the system, it could not complete in time.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156