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

时间:2012-11-20 07:55:38

标签: c# dynamics-crm-2011 workflow-activity

我有以下代码来获取实体记录:

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];
    }

当我调试时,到达此函数的最后一行eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0];它给出了一个异常:

属性'campaign.campaignid'的条件:'System.Guid'类型的预期参数,但收到'System.String []'。

请建议。

1 个答案:

答案 0 :(得分:2)

您将字符串数组作为EntityId的值传递。

改变这个:

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

到此:

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

您可能还想考虑将输入参数的类型更改为Guid并将Pascal Casing on EventId参数修复为camel以保持一致性