Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

I´m Trying to Write a String in a Field C#

Posted on by Microsoft Employee

using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using System.Text.RegularExpressions;

namespace ActivityLibrary1
{
    public sealed class KleinerTest : CodeActivity
    {
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            tracingService.Trace("test");
            Guid ID = context.PrimaryEntityId;
            Entity Entity = service.Retrieve("account", ID, new ColumnSet(true));
            string input = "Testobjekt";
            Entity["new_historie"] = input;
            service.Update(Entity);
        }
    }
}

_____________________________________________________________________________

Error:

Unexpected exception from plug-in (Execute): ActivityLibrary1.KleinerTest: System.AggregateException: One or more errors occurred.

Unhandled Exception: Microsoft.Crm.CrmException: Unexpected exception from plug-in (Execute): ActivityLibrary1.KleinerTest: System.AggregateException: One or more errors occurred.
   at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
   at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I´m Trying to Write a String in a Field C#

    Probably error not related to string field (also, check that new_historie is really string field, just to be sure) . You retrieved all columns and it means that when you update record you will update all retrieved fields with same value. And it means that all workflows and plugins related to this fields will be triggered.

    So:

    * Try to update only  new_historie field. It there is no error, it means error related to other fields

    * Check all plugins and workflows, determine what is triggered when you update entity, try to locate your error.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I´m Trying to Write a String in a Field C#

    I want to get all fields because i´m just testing

    It is a Custom Workflow activity

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans