用于检索和显示值的 MS Dynamics 简单自定义活动插件将无法工作

问题描述 投票:0回答:1

忽略这个插件的名称,因为此时我只想实现一些非常简单的东西,然后我可以从中构建更复杂的东西。但即使是最简单的事情也行不通。我对插件和自定义活动还很陌生,所以如果有人能指出我做错了什么,我将非常感激。首先,这是此自定义活动的代码,此时我只是尝试检索

contactid
,将其转换为字符串,然后在运行工作流程后能够在某个字符串字段中显示它需求:

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;

namespace WheatonPluginDelta.Activities
{
    public class RetrieveRaceOfPerson : CodeActivity
    {
        //Required input:
        [RequiredArgument]
        [Input(PersonReference)]
        [ReferenceTarget(contact)]
        public InArgument<EntityReference> PersonRef { get; set; }
 
        [Output(StringTest2)]
        public OutArgument<string> StringTest2 { get; set; }

        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService orgService = serviceFactory.CreateOrganizationService(workflowContext.UserId);

            EntityReference personRef = PersonRef.Get(executionContext);
            var contact = orgService.Retrieve(contact, personRef.Id, new ColumnSet(contactid));
            StringTest2.Set(executionContext, contact[contactid].ToString());
        }
    }
}

这是此自定义活动的设置,它要求输入工作流程:

input

然后我将自定义活动的输出设置为 StringTest2,以转到字符串类型的任何其他字段。然后我按需运行工作流程,还是不行!该字段不会填充此人的

contactid

有人可以告诉我我在这么简单的事情上做错了什么吗?

谢谢。

c# plugins dynamics-crm microsoft-dynamics custom-activity
1个回答
0
投票

我相信你只是错过了一些双引号 - Dynamics 中的许多东西都是字符串文字/常量 - 你的帖子没有显示任何这些 - 只是因为你真的不使用任何双引号,或者你是否以某种方式遗漏了这些什么时候发帖?

看一下这段代码:

public class RetrieveRaceOfPerson : CodeActivity
{
    //Required input:
    [RequiredArgument]
    [Input("PersonReference")]     // double quotes here - this is a string as name
    [ReferenceTarget("contact")]   // double quotes here, too - around the type of entity
    public InArgument<EntityReference> PersonRef { get; set; }

    [Output("StringTest2")]        // again double quotes 
    // I recommend using a *different* name than inside the [Output()] attribute
    public OutArgument<string> outStringTest2 { get; set; }  

    protected override void Execute(CodeActivityContext executionContext)
    {
        ITracingService tracingService = executionContext.GetExtension<ITracingService>();
        IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
        IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
        IOrganizationService orgService = serviceFactory.CreateOrganizationService(workflowContext.UserId);

        EntityReference personRef = PersonRef.Get(executionContext);

        // double quotes around the entity type to retrieve ....
        var contact = orgService.Retrieve("contact", personRef.Id, new ColumnSet(contactid));

        // double quotes around the attribute name
        outStringTest2.Set(executionContext, contact["contactid"].ToString());
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.