web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

productpricelevel does not exist

(0) ShareShare
ReportReport
Posted on by

Hi all

I was working on and create and update workflow plugin and seem to have run into an issue of the plugin not finding the productpricelevel i thought i had matched the correct entity id but not convinced now. I think it's looking at the actual price list id. any guidance would be helpful. Below is a condensed section of the plugin and where the issue i believe must lie and think the main suspect to be the following line

newProductPriceLevelEntity.Id = newPriceLevel.Id;

// 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(newProductPriceLevelEntity["productnumber"]);
newProductPriceLevelEntity.Id = newPriceLevel.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 == "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:

newProductPriceLevelEntity["amount"] = new Money(costamount);

service.Update(newProductPriceLevelEntity);

Many Thanks

Dan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

     Hi Dan,

    I am no expert but am learning how to code in CRM and challenged myself to debug your code. Not sure if I have a handle on it quite yet but something stood out to me straight away.

    newPriceLevel is a Price Level entity record (I assume so, since the declaration is omitted from your snippet).

    newProductPriceLevelEntity is a Product Price Level entity.

    So I think that you are right in your assumption that the line newProductPriceLevelEntity.Id = newPriceLevel.Id is the problem. It appears that you are trying to assign the GUID of an existing entity to a new record of a different entity type.

    Also, as far as I know, you can only use the Update method on an existing record. newProductPriceLevelEntity only exists in memory. You would have to call the Create method first (which would create the record in CRM and assign it a new GUID.

    However, I might be talking out of my hat because I'm only learning at this stage. I hope I have been of some help.

    Good Luck.

  • Community Member Profile Picture
    on at

    Morning Brad

    Thank you for your reply. It sounds like your at the same stage as me just learning,

    I do have some logic in the work flow in that it runs a create as a first instance and then leaves a flag to say it has been created then any future changes run through this update.

    How would i get the current productpricelevel.id would this be newProductPriceLevelEntity.Id = ProductPriceLevel.Id

    Many Thanks

    Dan

  • Anchal Profile Picture
    on at

    Hello Dan,

    Use this

    newProductPriceLevelEntity.Id = productPriceLevelList.Entities[index].Id; in place of newProductPriceLevelEntity.Id = newPriceLevel.Id;

  • Community Member Profile Picture
    on at

    Hi Anchal

    That is definitely a step forward but the prices don't update but thinking about it do i now need to make it update the ProductPricelevelList so the second to last line would be last line would be productPriceLevelList.Entities[index]["amount"] = new Money(costamount);

    and then would i update the service.Update(productPriceLevelList.Entities[index]);

    Regards

    Dan

  • Community Member Profile Picture
    on at

    Hi,

    Anchal beat me to the punch. I noticed that for each of the entries in productPriceLevelList, you are attempting to update an entity with the same Id (stored in newPriceLevel). Can you share with us how newPriceLevel is declared and what entity type it is?

    Can you please confirm the following?

    Is currentPriceLevelEntity passed to the function by a parameter?

    What is the entity type of currentPriceLevelEntity?

    Where and how is newPriceLevel declared/assigned.

    What is the end-game - are you just trying to update the "amount" for each of the records in productPriceLevelList?

  • Community Member Profile Picture
    on at

    Hi Brad

    The way i'm trying to get it working has a 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 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 input. In the second instance where the user would like to update the prices the fields(flag) is set to 1 so it runs the update plugin.

    So to answer your question the end game for this solution is to update the amounts for the records on the current pricelist in therory (productPriceleveList)

    Just for information the way in the create and how the newpricelevel is declared is below

    // 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_manholerun"] = manholerun.Get<int>(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);

    Kind Regards

    Dan

  • Community Member Profile Picture
    on at

    Hi all

    Any ideas the best way to get this to update the products as described above

    Many thanks for your help

    Dan

  • Community Member Profile Picture
    on at

    Am I right in thinking I need to remove the fact it's looking at another price list and make it look at it's own. How would I go about doing this

    Regards

    Dan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 2

#1
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

#1
Shidin Haridas Profile Picture

Shidin Haridas 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans