Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Error I´m trying to write a value into a text field

$
0
0

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

namespace dri_supportCheckGen
{
    public sealed class test : CodeActivity
    {
        public OptionSetValue neu = new OptionSetValue(100000000);
        public OptionSetValue bearbeitet = new OptionSetValue(100000001);
        public OptionSetValue geprüft = new OptionSetValue(100000002);
        int Option;
        String Historie;

        protected override void Execute(CodeActivityContext executionContext)
        {
            //Initialisiere Tracing Service
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            //Der sprung von der Entität "Supportcheck" in die Entität "Systeme"
            Guid contactID = context.PrimaryEntityId;
            Entity contact = service.Retrieve("contact", contactID, new ColumnSet(true));
            tracingService.Trace("2");
            DateTime now = DateTime.Now;
            tracingService.Trace("3");
            TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
            tracingService.Trace("4");
            now = new DateTime(now.Year, now.Day, now.Month, now.Hour, now.Minute, 0);
            tracingService.Trace("5");
            now = TimeZoneInfo.ConvertTime(now, tz);
            tracingService.Trace("6");
            tracingService.Trace("{0}", now);
            Historie = contact["new_historie"].ToString();
            Option = ((OptionSetValue)contact["new_pick"]).Value;
            tracingService.Trace("7");
            switch (Option)
            {
                case 100000000:
                    calcIncident0(service, tracingService, contact, now, Historie);

                    break;
                case 100000001:
                    calcIncident1(service, tracingService, contact, now, Historie);

                    break;
                case 100000002:
                    calcIncident2(service, tracingService, contact, now, Historie);

                    break;
            }
        }   
            private static void calcIncident0(IOrganizationService service, ITracingService tracingService, Entity contact, DateTime now,String Historie)
        {
            tracingService.Trace("8");
            Historie = "Der Kontakt"+ contact.FormattedValues["fullname"].ToString() + "wurde am"+now+"erstellt ! \n".ToString();
            tracingService.Trace("8,1");
            service.Update(contact);
        }
        private static void calcIncident1(IOrganizationService service, ITracingService tracingService, Entity contact, DateTime now, String Historie)
        {
            tracingService.Trace("9");
            contact["new_historie"] = "Der Kontakt" + contact.FormattedValues["fullname"].ToString() + "wurde am" + now + "geändert ! \n";
            service.Update(contact);
        }
        private static void calcIncident2(IOrganizationService service, ITracingService tracingService, Entity contact, DateTime now, String Historie)
        {
            tracingService.Trace("10");
            contact["new_historie"] = "Der Kontakt" + contact.FormattedValues["fullname"].ToString() + "wurde am" + now + "geprüft ! \n";
            service.Update(contact);
        }
    }
}


_______________________________________________________________________________________________________________

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): dri_supportCheckGen.test: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147220956</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>Unexpected exception from plug-in (Execute): dri_supportCheckGen.test: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.</Message>
<Timestamp>2016-11-01T14:42:23.5282712Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>
2
3
4
5
6
01/11/2016 15:42:00
</TraceText>
</OrganizationServiceFault>

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Crm.Sandbox.ISandboxHost.ExecuteCustomWorkflowActivityAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCustomActivity.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>