简体   繁体   English

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

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

I need to update Name field in Pricing Approval Products using ssis. 我需要使用ssis更新“定价批准产品”中的“名称”字段。 This is my Code in script component. 这是我的脚本组件代码。

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

But I got an exception: Entity reference cannot have id and key attributes empty. 但是我有一个例外:实体引用不能将id和key属性为空。 But my name field in crm is text field tho. 但是我在crm中的名称字段是文本字段tho。 I also using check ` 我也使用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);
    }

My breakpoint skip this code if (AppProductLookup != Guid.Empty) . if (AppProductLookup != Guid.Empty)我的断点将跳过此代码。 Thus I got no error, but thats not what I want. 因此,我没有错误,但是那不是我想要的。 I have NO idea what is wrong. 我不知道怎么了。 So I am a bit lost here. 所以我在这里有点迷路。

在此处输入图片说明

在此处输入图片说明

As an alternative to this, I solved my issue by Define alternate keys for Pricing Approval Products entity and Use UpsertRequest to insert or update a record in CRM. 作为替代方案,我通过为定价产品的实体定义备用键并使用UpsertRequest在CRM中插入或更新记录来解决了我的问题。 Please note Alternate key and UpsertRequest only applies to Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online. 请注意, Alternate keyUpsertRequest仅适用于Dynamics 365(在线),Dynamics 365(本地),Dynamics CRM 2016,Dynamics CRM Online。

暂无
暂无

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

相关问题 如何使用ssis的脚本组件将票证编号(查找字段)插入MS Dynamics CRM定价批准产品(自定义实体) - How to insert Ticket Number(lookup field) to MS Dynamics CRM Pricing Approval Products(Custom entity) using ssis's script component 如何使用CRM Dynamics 2013/2015中的插件用相关实体更新CRM中的实体 - How to update an Entity in CRM with a related Entity using a plug-in in CRM Dynamics 2013/2015 如何通过API在CRM Dynamics中创建自定义实体本身 - How to create custom entity itself in CRM Dynamics via API 使用 C# 更新 CRM 中的实体字段 - Update an Entity field in CRM using C# 如何使用C#在MS Dynamics CRM中为案例的自定义字段设置/获取值 - how to set/get value to the custom field of a case in MS Dynamics CRM using C# 程序集(插件)未触发联系人实体 Dynamics 365 CRM 中的 Web 角色(自定义实体)更新 - Assembly(Plugin) is not triggering on web roles (custom entity) update in contact entity Dynamics 365 CRM 如何在 Dynamics CRM 2016 中使用 DiscoveryService 获取实体中的项目列表? - How to get list of items in an entity using DiscoveryService in Dynamics CRM 2016? 如何使用Web服务在Dynamics CRM 4中删除实体链接 - How to delete entity link in Dynamics CRM 4 using webservices 实体删除前的 Dynamics CRM 自定义工作流程 - Dynamics CRM custom workflow before entity deletion Dynamics CRM SDK过滤自定义字段的查询 - Dynamics CRM SDK filter query on custom field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM