Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Modifying SDK Price Calc

$
0
0

Morning

I have been having a look at doing the weights of product items again. I saw the Price Calc in the SDK and thought with a bit of tweaking this could do what i needed. I have put my code below but it seems to do nothing. Ive checked all the field names to ensure i didn't make an error. Other than that i can't see why this wouldn't work

using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace StantonBonna
{
public partial class QuoteDelCalc : BasePlugin
{
public QuoteDelCalc(string unsecureConfig, string secureConfig) : base(unsecureConfig, secureConfig)
{
// Register for any specific events by instantiating a new instance of the 'PluginEvent' class and registering it
base.RegisteredEvents.Add(new PluginEvent()
{
Stage = eStage.PostOperation,
MessageName = MessageNames.CalculatePrice,
EntityName = EntityNames.quote,
PluginAction = ExecutePluginLogic
});
}
public void ExecutePluginLogic(IServiceProvider serviceProvider)
{
// Use a 'using' statement to dispose of the service context properly
// To use a specific early bound entity replace the 'Entity' below with the appropriate class type
using (var localContext = new LocalPluginContext<Entity>(serviceProvider)) ;
}
// Method to calculate price in a quote
private static void CalculateQuote(EntityReference entity, IOrganizationService service)
{
Entity e = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("statecode"));
OptionSetValue statecode = (OptionSetValue)e["statecode"];
if (statecode.Value == 0)
{
ColumnSet columns = new ColumnSet();
columns.AddColumns("sb_prodweight");
Entity quote = service.Retrieve(entity.LogicalName, entity.Id, columns);

QueryExpression query = new QueryExpression("quotedetailsGrid");
query.ColumnSet.AddColumns("sb_prodweight");
query.Criteria.AddCondition("quoteid", ConditionOperator.Equal, entity.Id);
EntityCollection ec = service.RetrieveMultiple(query);
quote["sb_deliverableweight"] = 0;

decimal total = 0;

for (int i = 0; i < ec.Entities.Count; i++)
{
total = total + ((decimal)ec.Entities[i]["sb_prodweight"]);
service.Update(ec.Entities[i]);
}

quote["sb_deliverableweight"] = (total);
}
}

}
}

Regards


Dan


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>