繁体   English   中英

如何使用ssis脚本组件更新Dynamics CRM中定价批准产品(自定义实体)中的“名称”字段

[英]How to update Name field in Pricing Approval Products(Custom Entity) in Dynamics CRM using ssis script component

我需要使用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中的名称字段是文本字段tho。 我也使用check`

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)我的断点将跳过此代码。 因此,我没有错误,但是那不是我想要的。 我不知道怎么了。 所以我在这里有点迷路。

在此处输入图片说明

在此处输入图片说明

作为替代方案,我通过为定价产品的实体定义备用键并使用UpsertRequest在CRM中插入或更新记录来解决了我的问题。 请注意, Alternate keyUpsertRequest仅适用于Dynamics 365(在线),Dynamics 365(本地),Dynamics CRM 2016,Dynamics CRM Online。

暂无
暂无

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

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