I don't understand what you mean by real code. That was the real code but i just trimmed down to where i thought the actual information that is useful is. I have add more of the code below but after the last line it's just adding the data so not much use really.
The simplest way to explain is that currently the user goes to a entity i created fills in the information and then clicks save which triggers the creation of a new price list based on a few bits of information the user has provided. basically three inputed prices can give the values of 50 parts
I would like to move this into the price list entity so the user can add the above information to an existing price list saving the need for multiple price lists for the same account
Hope that makes more sense. Please see more of the code below. Thank you for your help and time in replying
Dan
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;
using System;
namespace pluginprofile
{
public class Updatepricelist : 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("pricelevel");
currentPriceLevelEntity = service.Retrieve("pricelevel", CurrentPriceList.Get<EntityReference>(executionContext).Id, attributes);
// Create New Price List
Entity newPriceLevel = new Entity("pricelevel");
newPriceLevel["name"] = NewPriceListName.Get<string>(executionContext);
newPriceLevel["sb_fpaid"] = Contractor.Get<string>(executionContext);
newPriceLevel["sb_merchant"] = Merchant.Get<string>(executionContext);
newPriceLevel["transactioncurrencyid"] = currentPriceLevelEntity["transactioncurrencyid"];
Guid newPriceLevelId = service.Create(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);
// 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", newPriceLevelId);
newProductPriceLevelEntity["productid"] = productPriceLevelList.Entities[index]["productid"];
newProductPriceLevelEntity["uomid"] = productPriceLevelList.Entities[index]["uomid"];
string prodidse = newProductPriceLevelEntity.GetAttributeValue<EntityReference>("productid").Name;
//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;