如何使用 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 中的姓名字段是文本字段。我也使用检查`
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)
。因此我没有错误,但这不是我想要的。
我不知道出了什么问题。所以我在这里有点迷路。
作为替代方案,我通过 Define alternate keys for Pricing Approval Products entity and Use UpsertRequest 在 CRM 中插入或更新记录解决了我的问题。请注意 Alternate key
和 UpsertRequest
仅适用于 Dynamics 365(在线)、Dynamics 365(本地)、Dynamics CRM 2016、Dynamics CRM Online。
我需要使用 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)
。因此我没有错误,但这不是我想要的。
我不知道出了什么问题。所以我在这里有点迷路。
作为替代方案,我通过 Define alternate keys for Pricing Approval Products entity and Use UpsertRequest 在 CRM 中插入或更新记录解决了我的问题。请注意 Alternate key
和 UpsertRequest
仅适用于 Dynamics 365(在线)、Dynamics 365(本地)、Dynamics CRM 2016、Dynamics CRM Online。