简体   繁体   English

自定义工作流活动功能错误

[英]Custom Workflow Activity Function Error

I have following code to fetch an entity records: 我有以下代码来获取实体记录:

private void FetchEvent(string EventId, IOrganizationService crmService)
    {
        // Create the ColumnSet to be retrieved.
        ColumnSet columnSet = new ColumnSet();
        // Set the properties of the ColumnSet.
        columnSet.AddColumn("campaignid");
        columnSet.AddColumn("name");
        columnSet.AddColumn("description");
        columnSet.AddColumn("renre_giftid");
        columnSet.AddColumn("ownerid");  

        // Create the FilterExpression.
        FilterExpression filterExpression = new FilterExpression();

        // Create the ConditionExpression.
        ConditionExpression conditionExpression = new ConditionExpression();

        // Set the condition for the retrieval based on customer id field.
        conditionExpression.AttributeName = "campaignid";
        conditionExpression.Operator = ConditionOperator.Equal;
        conditionExpression.Values.Add(new string[]{EventId});

        filterExpression.FilterOperator = LogicalOperator.And;
        // Set the properties of the filter.
        filterExpression.Conditions.Add(conditionExpression);

        // Create the QueryExpression object.
        QueryExpression queryExpression = new QueryExpression();

        // Set the properties of the QueryExpression object.
        queryExpression.EntityName = "campaign";//EntityName.campaign.ToString();
        queryExpression.ColumnSet = columnSet;
        queryExpression.Criteria = filterExpression;

        RetrieveMultipleRequest InvitationResponseRequest = new RetrieveMultipleRequest();
        InvitationResponseRequest.Query = queryExpression;
        //InvitationResponseRequest.ReturnDynamicEntities = true;

        eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0];
    }

When I debug, after reaching the last line of this function eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0]; 当我调试时,到达此函数的最后一行eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0]; It gives an exception that: 它给出了一个例外:

Condition for attribute 'campaign.campaignid': expected argument(s) of type 'System.Guid' but received 'System.String[]'. 属性'campaign.campaignid'的条件:'System.Guid'类型的预期参数,但收到'System.String []'。

Please suggest. 请建议。

You're passing a string array as the value of EntityId. 您将字符串数组作为EntityId的值传递。

Change this: 改变这个:

conditionExpression.Values.Add(new string[]{EventId});

to this: 对此:

conditionExpression.Values.Add(new Guid(EventId));

You might also want to think about changing the type on the input parameter to a Guid and fixing the Pascal Casing on EventId argument to camel for consistency 您可能还想考虑将输入参数的类型更改为Guid并将Pascal Casing on EventId参数修复为camel以保持一致性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM