i have created a plugin for updation of credit limit and creation of new credit card
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace AnnualIncome
{
public class AnnIncomePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "contact")
{
return;
}
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.Stage == 40)
{
if (entity.Contains("annualincome") && entity["annualincome"] != null && entity.Contains("dxc_country") && entity["dxc_country"] != null)
{
//annual income field
Money revenue = (Money)entity["annualincome"];
decimal revenue_value = revenue.Value;
double AnnIncome = (double)revenue.Value;
//country field
OptionSetValue country = (OptionSetValue)entity["dxc_country"];
int selectedOptionValue = country.Value;
String text = entity.FormattedValues["dxc_country"].ToString();
if (AnnIncome < 300000)
{
throw new InvalidPluginExecutionException("annual income must be more than 3 lakh");
}
else if (AnnIncome > 300000 && text == "India")
{
var Val1 = revenue_value * 0.35m;
string CreditcardLimit = Convert.ToString(Val1);
entity["dxc_creditlimit"] = CreditcardLimit;
service.Update(entity);
Entity contact = service.Retrieve(entity.LogicalName, entity.Id,new ColumnSet (true));
// creating a new credit card entity record
Entity NewCreditcard = new Entity("dxc_creditcard");
NewCreditcard["dxc_contact"] = new EntityReference("contact", entity.Id);
NewCreditcard["dxc_creditcardno"] = entity.Attributes["dxc_creditcard"];
NewCreditcard["dxc_creditcardtype"] = entity.Attributes["dxc_creditcardtype"];
NewCreditcard["dxc_status"] = entity.Attributes["dxc_status"];
service.Create(NewCreditcard);
}
}
}
}
}
}
}
error was coming for line (NewCreditcard["dxc_creditcardno"] = entity.Attributes["dxc_creditcard"];)
the credit card field in the contact entity was created by using a java script and its not assaigning its value to the credit card entity and alsoo in debugging i found out that there is no dxc_creditcard field why is that??