Dynamics crm 2011 插件无法激活工作流(系统xaml WF使用c#) 列表项

Dynamics crm 2011 插件无法激活工作流(系统xaml WF使用c#) 列表项,dynamics-crm-2011,dynamics-crm-online,Dynamics Crm 2011,Dynamics Crm Online,1.>我已经创建了新插件(在创建和更新任何自定义实体时启动(假设:ce1)) 2.>在在线版本中注册 3.>该插件创建工作流(使用c#代码的系统xaml工作流)并激活 那是WF 4.>WF正在创建F9:) 问题是…:( 6.>使用不同的C#应用程序,仅创建WF而未在在线版本中激活(即WF处于草稿模式) 7.>但它在本地版本f9中工作 8.>它在f9中在线工作,但使用CRM界面 9.>使用C#应用程序时,在WF将被激活的行上抛出一个错误…错误是:模拟时无法发布工作流 非常感谢您的帮助…请帮助我 谢

1.>我已经创建了新插件(在创建和更新任何自定义实体时启动(假设:ce1))

2.>在在线版本中注册

3.>该插件创建工作流(使用c#代码的系统xaml工作流)并激活 那是WF

4.>WF正在创建F9:)

问题是…:(

6.>使用不同的C#应用程序,仅创建WF而未在在线版本中激活(即WF处于草稿模式)

7.>但它在本地版本f9中工作

8.>它在f9中在线工作,但使用CRM界面

9.>使用C#应用程序时,在WF将被激活的行上抛出一个错误…错误是:模拟时无法发布工作流

非常感谢您的帮助…请帮助我


谢谢。

发布您的插件代码会很有帮助。但是如果您使用插件上下文获取IOrganizationService,它可能会使用模拟,如果是这样,我会尝试创建一个具有正确所有者的新OrganizationServiceProxy,看看这是否解决了问题

我没有访问在线版本的权限,因此这是一个暗中操作。

//在插件中获得服务
//Getting Service as happens in PLUGIN
IOrganizationServiceFactory serviceFactory =          (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
  IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

//Configuring xaml to create workflow    

 string xamlWfPrefix = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Activity x:Class=""XrmWorkflow"" 
xmlns=""http://schemas.microsoft.com/netfx/2009/xaml/activities"" 
xmlns:mva=""clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""
xmlns:mxs=""clr-namespace:Microsoft.Xrm.Sdk;assembly=Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
xmlns:mxswa=""clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""
xmlns:s=""clr-namespace:System;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" 
xmlns:scg=""clr-namespace:System.Collections.Generic;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" 
xmlns:srs=""clr-namespace:System.Runtime.Serialization;assembly=System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""
xmlns:this=""clr-namespace:"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <x:Members>
    <x:Property Name=""InputEntities"" Type=""InArgument(scg:IDictionary(x:String, mxs:Entity))"" />
    <x:Property Name=""CreatedEntities"" Type=""InArgument(scg:IDictionary(x:String, mxs:Entity))"" />
  </x:Members>
  <this:XrmWorkflow.InputEntities>
    <InArgument x:TypeArguments=""scg:IDictionary(x:String, mxs:Entity)"" />
  </this:XrmWorkflow.InputEntities>
  <this:XrmWorkflow.CreatedEntities>
    <InArgument x:TypeArguments=""scg:IDictionary(x:String, mxs:Entity)"" />
  </this:XrmWorkflow.CreatedEntities>
  <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
  <mxswa:Workflow>
    <Sequence DisplayName=""CreateStep1"">
      <Sequence.Variables>
        <Variable x:TypeArguments=""x:Object"" Name=""CreateStep1_1"" />
        <Variable x:TypeArguments=""x:Object"" Name=""CreateStep1_2"" />
      </Sequence.Variables>
      <Assign x:TypeArguments=""mxs:Entity"" To=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" Value=""[New Entity(&quot;new_crm_new_sfeed&quot;)]"" />
      <mxswa:ActivityReference AssemblyQualifiedName=""Microsoft.Crm.Workflow.Activities.EvaluateExpression, Microsoft.Crm.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" DisplayName=""EvaluateExpression"">
        <mxswa:ActivityReference.Arguments>
          <InArgument x:TypeArguments=""x:String"" x:Key=""ExpressionOperator"">CreateCrmType</InArgument>
          <InArgument x:TypeArguments=""s:Object[]"" x:Key=""Parameters"">[New Object() { Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String, """;

                    xamlWfPrefix += displayname + @""", ""String"" }]</InArgument>
          <InArgument x:TypeArguments=""s:Type"" x:Key=""TargetType"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
          <OutArgument x:TypeArguments=""x:Object"" x:Key=""Result"">[CreateStep1_1]</OutArgument>
        </mxswa:ActivityReference.Arguments>
      </mxswa:ActivityReference>
      <mxswa:SetEntityProperty Attribute=""new_name"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" Value=""[CreateStep1_1]"">
        <mxswa:SetEntityProperty.TargetType>
          <InArgument x:TypeArguments=""s:Type"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
        </mxswa:SetEntityProperty.TargetType>
      </mxswa:SetEntityProperty>
      <mxswa:ActivityReference AssemblyQualifiedName=""Microsoft.Crm.Workflow.Activities.EvaluateExpression, Microsoft.Crm.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" DisplayName=""EvaluateExpression"">
        <mxswa:ActivityReference.Arguments>
          <InArgument x:TypeArguments=""x:String"" x:Key=""ExpressionOperator"">CreateCrmType</InArgument>
          <InArgument x:TypeArguments=""s:Object[]"" x:Key=""Parameters"">[New Object() { Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String, """;

                    xamlWfPrefix += displayname;

                    string xamlWfSuffix = @", ""String"" }]</InArgument>
          <InArgument x:TypeArguments=""s:Type"" x:Key=""TargetType"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
          <OutArgument x:TypeArguments=""x:Object"" x:Key=""Result"">[CreateStep1_2]</OutArgument>
        </mxswa:ActivityReference.Arguments>
      </mxswa:ActivityReference>
      <mxswa:SetEntityProperty Attribute=""new_description"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" Value=""[CreateStep1_2]"">
        <mxswa:SetEntityProperty.TargetType>
          <InArgument x:TypeArguments=""s:Type"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
        </mxswa:SetEntityProperty.TargetType>
      </mxswa:SetEntityProperty>
      <mxswa:CreateEntity EntityId=""{x:Null}"" DisplayName=""CreateStep1"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" />
      <Assign x:TypeArguments=""mxs:Entity"" To=""[CreatedEntities(&quot;CreateStep1_localParameter&quot;)]"" Value=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" />
      <Persist />
    </Sequence>
  </mxswa:Workflow>
</Activity>";

       //Calling method to create total xaml code that requires to create workflow
       string xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordCreated);
        //Initiating workflow to be create
        Workflow wfOnCreate = new Workflow()
              {
                Name = "CRM_DNNWorkflow_OnCreate",
                Type = new OptionSetValue(1),
                Category = new OptionSetValue(0),
                Scope = new OptionSetValue(2),
                LanguageCode = 1033, // U.S. English
                TriggerOnCreate = true,
                OnDemand = false,
                PrimaryEntity = logicalname, //Name of entity on which WF will be fired
                Description = @"Tracks Creation",
                Xaml = xamlWf
                    };


                    xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordDeleted);
                   //Another WF
                    Workflow wfOnDelete = new Workflow()
                    {
                        Name = "CRM_DNNWorkflow_OnDelete",
                        Type = new OptionSetValue(1),
                        Category = new OptionSetValue(0),
                        Scope = new OptionSetValue(2),
                        LanguageCode = 1033, // U.S. English
                        TriggerOnDelete = true,
                        OnDemand = false,
                        PrimaryEntity = logicalname,
                        Description = @"Tracks Deletion",
                        Xaml = xamlWf
                    };


                    xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordModified);
                    //Another WF
                    Workflow wfOnModify = new Workflow()
                    {
                        Name = "CRM_DNNWorkflow_OnModify",
                        Type = new OptionSetValue(1),
                        Category = new OptionSetValue(0),
                        Scope = new OptionSetValue(2),
                        LanguageCode = 1033, // U.S. English
                        TriggerOnUpdateAttributeList = attributeList,
                        OnDemand = false,
                        PrimaryEntity = logicalname,
                        Description = @"Tracks Modification",
                        Xaml = xamlWf
                    };


                    workflowOnCreateId = service.Create(wfOnCreate);
                    workflowOnDeleteId = service.Create(wfOnDelete);
                    workflowOnModifyId = service.Create(wfOnModify);           

                    //activate workflow (OnCreate)
                    ActivateWorkflow(workflowOnCreateId, service, serviceProvider);

                    //activate workflow (OnDelete)
                    ActivateWorkflow(workflowOnDeleteId, service, serviceProvider);

                    //activate workflow (OnModify)
                    ActivateWorkflow(workflowOnModifyId, service, serviceProvider);
                }
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                tracingService.Trace("Exception: {0}", ex.ToString());
                throw;
                //throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }
        }



        /// <summary>
        /// Builds the Xaml to define the function of a Workflow.
        /// </summary>
        /// <param name="prefix">Prefix to Xaml code</param>
        /// <param name="suffix">Suffix to Xaml code</param>
        /// <param name="status">Sets the description field of the new_crm_new_sfeed Entity</param>
        /// <returns></returns>
        private string BuildWorkflowXaml(string prefix,string suffix,string status)
        {
            return prefix + status + suffix;
        }



        /// <summary>
        /// Activates a Workflow.
        /// </summary>
        /// <param name="workflowId">Guid of the workflow to be created.</param>
        /// <param name="service">IOrganizationService Object.</param>
        private void ActivateWorkflow(Guid workflowId,IOrganizationService service,IServiceProvider serviceProvider) 
        {
            //Extract the tracing service for use in plug-in debugging.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            try
            {
                SetStateRequest activateRequest = new SetStateRequest
                {
                    EntityMoniker = new EntityReference(Workflow.EntityLogicalName, workflowId),
                    State = new OptionSetValue((int)WorkflowState.Activated),
                    Status = new OptionSetValue(2)
                };
                //**Error Occurs Here**
                OrganizationResponse respActivation = service.Execute(activateRequest);
                tracingService.Trace("ActivateResponse", respActivation);
                workflowGUIDs.Add(workflowId);
            }
            catch (InvalidPluginExecutionException exe)
            {
                tracingService.Trace("Exception: {0}", exe.ToString());
                throw;
            }            
        }





**FROM MY C# APPLICATION**



// Form the RetrieveOrganization Request.
   RetrieveOrganizationRequest request = new RetrieveOrganizationRequest();
   request.UniqueName = organizationUniqueName;
   RetrieveOrganizationResponse response = (RetrieveOrganizationResponse)discoveryServiceProxy.Execute(request);

// Form the URL.
   Uri uri = new Uri(response.Detail.Endpoints[EndpointType.OrganizationService]);

 //Form the OrganizationServiceProxy Object.
   orgServiceProxy = new OrganizationServiceProxy(uri, null, discoveryServiceProxy.ClientCredentials, discoveryServiceProxy.DeviceCredentials);


Entity Dnn_selectedEntity = new Entity("new_dnn_selected_entity");
Dnn_selectedEntity["new_name"] = entityMetadataId.Value.ToString();
Dnn_selectedEntity["new_trackedentity"] = entityMetadataId.Key;
orgServiceProxy.Create(Dnn_selectedEntity);
//After Creting this record That Plugin fires....



Thanks.
IOOrganizationServiceFactory serviceFactory=(IOOrganizationServiceFactory)serviceProvider.GetService(类型为(IOOrganizationServiceFactory)); IOOrganizationService=serviceFactory.CreateOrganizationService(context.UserId); //配置xaml以创建工作流 字符串xamlWfPrefix=@” 用于内部实现的程序集引用和导入的命名空间 CreateCrmType [新对象(){Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String”“; xamlWfPrefix+=displayname+@“”,“字符串”}] [创建步骤1_1] CreateCrmType [新对象(){Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String”“; xamlWfPrefix+=显示名称; 字符串xamlWfSuffix=@“,”字符串“}] [创建步骤1_2] "; //调用方法以创建创建工作流所需的全部xaml代码 字符串xamlWf=BuildWorkflowXaml(xamlWfPrefix,xamlWfSuffix,recordCreated); //正在启动要创建的工作流 工作流wfOnCreate=新工作流() { Name=“CRM\u DNNWorkflow\u OnCreate”, 类型=新选项设置值(1), 类别=新选项设置值(0), 范围=新选项设定值(2), LanguageCode=1033,//美国英语 TriggerOnCreate=true, OnDemand=false, PrimaryEntity=logicalname,//将对其激发WF的实体的名称 Description=@“轨道创建”, Xaml=xamlWf }; xamlWf=BuildWorkflowXaml(xamlWfPrefix,xamlWfSuffix,recordDeleted); //另一个WF 工作流wfOnDelete=新工作流() { Name=“CRM\u DNNWorkflow\u OnDelete”, 类型=新选项设置值(1), 类别=新选项设置值(0), 范围=新选项设定值(2), LanguageCode=1033,//美国英语 TriggerOnDelete=true, OnDemand=false, PrimaryEntity=logicalname, Description=@“跟踪删除”, Xaml=xamlWf }; xamlWf=BuildWorkflowXaml(xamlWfPrefix,xamlWfSuffix,recordModified); //另一个WF 工作流wfOnModify=新工作流() { Name=“CRM\u DNNWorkflow\u OnModify”, 类型=新选项设置值(1), 类别=新选项设置值(0), 范围=新选项设定值(2), LanguageCode=1033,//美国英语 TriggerUpdateAttributeList=属性列表, OnDemand=false, PrimaryEntity=logicalname, Description=@“轨道修改”, Xaml=xamlWf }; workflowOnCreateId=service.Create(wfOnCreate); workflowOnDeleteId=service.Create(wfOnDelete); workflowOnModifyId=service.Create(wfOnModify); //激活工作流(OnCreate) ActivateWorkflow(workflowOnCreateId、服务、服务提供者); //激活工作流(OnDelete) ActivateWorkflow(workflowOnDeleteId、服务、服务提供者); //激活工作流(OnModify) ActivateWorkflow(workflowOnModifyId、服务、服务提供者); } } 捕获(FaultException-ex) { tracingService.Trace(“异常:{0}”,例如ToString()); 投掷; //抛出新的InvalidPluginExecutionException(“插件中发生错误。”,ex); } } /// ///构建Xaml以定义工作流的功能。 /// ///Xaml代码的前缀 ///Xaml代码的后缀 ///设置新\u crm\u新\u sfeed实体的描述字段 /// 私有的