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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error in Plugin stating as "Incorrect System.Decimal"

(0) ShareShare
ReportReport
Posted on by

Hi,

As I am new to plugin , I have got this error. My scenario is to create the values by retrieving from the parent entity (custom) "Acc" to child (custom) entity "Con". When Acc entity's form values gets saved, this plugin should get triggered and those field values should be automatically created in the Con entity as well. I have used the data types such as Integer, String, Optionset and decimal in the both the entities matching them.

when I saved,I got the error log, and when I debugged it using Profiling, I got the error as "Incorrect System.Decimal". I guessed that the error should be in the Decimal datatype, which I have used in the three fields such as new_UGPercentage,new_HSCPercentage and new_SSLCPercentage in the Acc entity. 

Please help me on this. Note: This plugin for Create function.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk; // Namespaces to be mentioned along with System.Runtime.Serialization by browsing in the assembly box
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel;


namespace Simple_create
{
    public class Class1 : IPlugin
    {
        // Variable declaration 
        int age;        //Integer declaration
        string name;    //String declaration
        string address;
        int phonenumber;
        OptionSetValue sex = new OptionSetValue();      // variable declaration syntax for optionset datatype
        OptionSetValue degree = new OptionSetValue();
        decimal hscpercentage;      // decimal declaration
        decimal ugpercentage = 0;
        decimal sslcpercentage;

        public void Execute(IServiceProvider serviceprovider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext)); // context is the place where all the fields and columnset is present with all the values
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = (IOrganizationService)factory.CreateOrganizationService(context.UserId);

            if (context.Depth > 1) // to avoid infinite loop
                return;

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) //registered data 
            {
                Entity entityrecord = (Entity)context.InputParameters["Target"]; //entity -> variable name
               // Entity entityrecord = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(true));

                if (entityrecord.LogicalName != "new_acc") //to be given against for which the plugin gonna be registered and check condition
                    return;

                //Various types of Datatype check to verify it contains some data or not

                if (entityrecord.Attributes.Contains("new_age") && entityrecord.Attributes["new_age"] != null)
                {
                    age = (Int32)(entityrecord.Attributes["new_age"]);      //Integer

                }

                if (entityrecord.Attributes.Contains("new_name") && entityrecord.Attributes["new_name"] != null)
                {
                    name = (string)entityrecord.Attributes["new_name"];     //String

                }

                if (entityrecord.Attributes.Contains("new_address") && entityrecord.Attributes["new_address"] != null)
                {
                    address = (string)(entityrecord.Attributes["new_address"]);     //String

                }

                if (entityrecord.Attributes.Contains("new_degree") && entityrecord.Attributes["new_degree"] != null)
                {
                    degree = (OptionSetValue)(entityrecord.Attributes["new_degree"]); //Optionset

                }

                    if (entityrecord.Attributes.Contains("new_hscpercentage") && entityrecord.Attributes["new_hscpercentage"] != null)
                    {
                        hscpercentage = Convert.ToDecimal(entityrecord.Attributes["new_hscpercentage"]); //decimal

                    }

                    if (entityrecord.Attributes.Contains("new_ugpercentage") && entityrecord.Attributes["new_ugpercentage"] != null)
                    {
                        ugpercentage = Convert.ToDecimal(entityrecord.Attributes["new_ugpercentage"]); //decimal

                    }

                    if (entityrecord.Attributes.Contains("new_sslcpercentage") && entityrecord.Attributes["new_sslcpercentage"] != null)
                    {
                        sslcpercentage = Convert.ToDecimal(entityrecord.Attributes["new_sslcpercentage"]); //decimal

                    }

                if (entityrecord.Attributes.Contains("new_sex") && entityrecord.Attributes["new_sex"] != null)
                {
                    sex = (OptionSetValue)(entityrecord.Attributes["new_sex"]); //Optionset

                }

                if (entityrecord.Attributes.Contains("new_phonenumber") && entityrecord.Attributes["new_phonenumber"] != null)
                {
                    phonenumber = (Int32)(entityrecord.Attributes["new_phonenumber"]); //Integer

                }


                // Setting the value of Parent entity ACC to child entity CON.

                Entity xxx = new Entity(); // entity obj creation
                xxx.LogicalName = "new_con";
                xxx["new_name"] = name;         // where the fields mentioned here are the destination entity (child entity) "Con"
                xxx["new_yourage"] = age;
                xxx["new_homeaddress"] = address;
                xxx["new_degreetype"] = degree;
                xxx["new_hscpercent"] = hscpercentage;
                xxx["new_ugpercent"] = ugpercentage;
                xxx["new_sslcpercent"] = sslcpercentage;
                xxx["new_yoursex"] = sex;
                xxx["new_contact"] = phonenumber;
                Guid xid = service.Create(xxx);



            }

            //OptionSetValue - optionsetvalue
            //lookup - EntityReference decimal Decimal boolean - bool
                //float - ParseFloat  money - Money

        }
    }
}

*This post is locked for comments

I have the same question (0)
  • Kishor Kumar Profile Picture
    3,710 on at

    Hi,

    Meiyappan Ram,

    Just try this,

    1.Check whether those three fileds are new_UGPercentage,new_HSCPercentage and new_SSLCPercentage of type is DecimalNumber

    2.  sslcpercentage = (Money)(entityrecord.Attributes["new_sslcpercentage"]);

  • Suggested answer
    ShahXu Profile Picture
    1,515 on at

    what are the datatype of new_UGPercentage,new_HSCPercentage and new_SSLCPercentage in CRM.

    try to debug it by commenting all three decimal fields and check record is created successfully if yes then open one by one and check which field is creating issue.

    and check the data type of that in CRM.

    there can be following possibilities..

    value may be null.

    crm is expecting any other value.

    just like u have creating field of floating number and providing decimal number value..

    i hope it will help u.

    mark my answer if issue resolves

  • Suggested answer
    meenoo Profile Picture
    7,316 on at

    Hi,

    Try getting the decimal value like this:

    hscpercentage=entityrecord.GetAttributeValue<decimal>("new_hscpercentage");

    and then assign like this:

    xxx["new_hscpercent"] = hscpercentage;  

    Thank you.

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans