0

我需要使用 ssis 更新定价批准产品中的名称字段。这是我在脚本组件中的代码。

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    Guid AppProductLookup = new Guid();
    AppProductLookup = getAppProductId(Row.Name, ref organizationservice);
    Entity AppProductEnt = new Entity("new_ticketproduct");
    ColumnSet columns = new ColumnSet(true);
    columns = new ColumnSet(new String[] { "new_name"});

    AppProductEnt = organizationservice.Retrieve(AppProductEnt.LogicalName, AppProductLookup, columns);
    AppProductEnt["new_name"] = Row.Name;
    organizationservice.Update(AppProductEnt);

}

public Guid getAppProductId(string name, ref IOrganizationService service)
{

    Guid AppProductId = Guid.Empty;
    QueryExpression AppProduct = new QueryExpression { EntityName = "new_ticketproduct", ColumnSet = new ColumnSet(true) };
    AppProduct.Criteria.AddCondition("new_name", ConditionOperator.Equal, name);
    EntityCollection AppProductRetrieve = service.RetrieveMultiple(AppProduct);

    if (AppProductRetrieve != null && AppProductRetrieve.Entities.Count > 0)
    {

        AppProductId = AppProductRetrieve.Entities[0].GetAttributeValue<Guid>("new_ticketproductid");

    }
    return AppProductId;
}

但我遇到了一个例外:实体引用不能有 id 和 key 属性为空。但是我在 crm 中的姓名字段是文本字段。我也使用检查`

if (AppProductLookup != Guid.Empty)
    {
        AppProductEnt = organizationservice.Retrieve(AppProductEnt.LogicalName, AppProductLookup, columns);
        AppProductEnt["new_name"] = Row.Name;
        organizationservice.Update(AppProductEnt);
    }
    else
    {
        //AppProductEnt["new_name"] = Row.Name;
        //organizationservice.Create(AppProductEnt);
    }

我的断点跳过这段代码if (AppProductLookup != Guid.Empty)。因此我没有错误,但这不是我想要的。我不知道出了什么问题。所以我在这里有点迷失了。

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

作为替代方案,我通过为 Pricing Approval Products 实体 定义备用键并使用UpsertRequest在 CRM 中插入或更新记录来解决我的问题。请注意Alternate key并且UpsertRequest仅适用于 Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online。

于 2017-10-04T14:37:22.963 回答