[英]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 key
和UpsertRequest
仅适用于Dynamics 365(在线),Dynamics 365(本地),Dynamics CRM 2016,Dynamics CRM Online。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.