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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve and assign Decimal Number field

(0) ShareShare
ReportReport
Posted on by

Hi, 

In C# plugin code,

- how to retrieve the value of a field of type 'Decimal Number' ?

- how to assign it a value?

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
  • Community Member Profile Picture
    on at

    Thanks guys,

    I tried it, it gives me the following error: This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again.

  • Mahendar Pal Profile Picture
    45,095 on at

    This is some other issue in your workflow, it not because of the decimal value, share your code here for inquiry

  • Community Member Profile Picture
    on at

    Here is the code:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Metadata;

    using Microsoft.Crm.Sdk;

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Query;

    namespace DecimalNumberTest

    {

       public class MyDecimalNumber : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               // Obtain the execution context from the service provider.

               Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)

                   serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

               IOrganizationServiceFactory wod_serviceFactory = null;

               IOrganizationService wod_CrmService = null;

               try

               {

                   wod_serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

                   wod_CrmService = wod_serviceFactory.CreateOrganizationService(context.UserId);

                   if (context.InputParameters.Contains("Target")

                   && context.InputParameters["Target"] is Entity)

                   {

                       Entity gitsPluginEntity = (Entity)context.InputParameters["Target"];

                       switch (context.MessageName)

                       {

                           case "Update":

                               if (gitsPluginEntity.LogicalName == "gits_violationrecord")  //mod

                               {

                                   decimal myNumber =  gitsPluginEntity.GetAttributeValue<decimal>("gits_decimalnumber");

                                   myNumber = myNumber + 1;

                                   gitsPluginEntity["gits_decimalnumber"] = myNumber;                                

                                   wod_CrmService.Update(gitsPluginEntity);

                               }

                               break;

                       }

                   }

               }

               catch (System.Web.Services.Protocols.SoapException ex)

               {

                   throw new InvalidPluginExecutionException(ex.Detail.InnerText);

               }

               catch (Exception ex)

               {

                   throw new InvalidPluginExecutionException(ex.Message);

               }

           }

       }

    }

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    First this is plugin not workflow, and you are trying to update in update message, that's why your plugin is going in infinite loop. You need to handle this case:

    > Either manage context.Depth  property  to avoid this situation, you can check this post it will help you to understand this: www.magnetismsolutions.com/.../crm-2011-plugins-avoiding-infinite-loops

    > Or try to register your code on preupdate, and don't use update method, you just need to add your property.

    Thanks

  • Verified answer
    P. R. M Profile Picture
    739 on at

    As per your code, you registered  the plug-in on Update message of gits_violationrecord entity and trying to update the same entity from the plug-in code. Hence, its going to infinite loop. Please do below to resolve this issue:

    1. Select the "Filtered attributes" for update step from plug-in registration tool. By this plug-in will fire only on updating the specified fields.

    2. Check for the context.depth == 1 in plug-in code before updating the record.

    Hope it helps you :)

  • Community Member Profile Picture
    on at

    Thanks all

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans