[英]How to insert Ticket Number(lookup field) to MS Dynamics CRM Pricing Approval Products(Custom entity) using ssis's script component
[英]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 key
和UpsertRequest
仅适用于Dynamics 365(在线),Dynamics 365(本地),Dynamics CRM 2016,Dynamics CRM Online。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.