Hi Friends,
I have a plugin on create written on a opportuninty form .
In that I have fields AnnualValue and AnnualValue_base of currency types. AnualValue_base is set to type USD dollar because default set of currency .
In form AnnualValue_base is hidden and user can enter Amount in Annual Value by selecting any currency type.
I have requirement is that user enter the value in AnnualValue and after some logic it should take value from AnnualValue_base and set it another field Revenue.
e.g
Annual value - 100 -- user enter the value in form
Currency type- Euro -- -- user enter the value in form
Annual Value_base($) - 117 -- Hidden(117 is setting by default)
Revenue = Annual Value_base($) * (some logic value)
ie = Revenue = 117 * 10 = $1170
But In plugin I am getting error at
Money AnnualVal = (Money)(entity.Attributes["annualvalue_base"]); //
//****************************************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace OnCreateCalculatesRevenue
{
public class CreateCalculatedRevenue:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//throw new NotImplementedException();
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.Depth > 1) { return; }
Entity entity = (Entity)context.InputParameters["Target"];
try
{
Money AnnualVal = (Money)(entity.Attributes["annualvalue_base"]);
decimal AnnualValue = AnnualVal.Value;
// some logic
decimal rev = AnnualValue * 100 * 12 ;
// some logic end
entity.Attributes["revenue1"] = rev ;
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred -in.", ex);
}
}
//****************************************************************************************************************
*This post is locked for comments