我需要在定价批准产品中创建或更新票号查找字段。此票号(查找字段)链接到另一个名为定价批准票的实体中的票(文本字段)。
这是我在脚本组件中的代码。
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Entity ApprovalProductEnt = new Entity("new_ticketproduct");
ColumnSet columns = new ColumnSet(true);
columns = new ColumnSet(new String[] { "new_ticket",
"new_productgroup",
"new_producttype",
"new_productitem" });
Guid TicketNumberId = new Guid();
TicketNumberId = getTicketNumber(Row.OppportunityID, ref organizationservice);
//update
if (TicketNumberId != Guid.Empty)
{
ApprovalProductEnt["new_ticket"] = new EntityReference("new_pricingapprovalticket", TicketNumberId);
}
else
//create
if (TicketNumberId != Guid.Empty)
{
ApprovalProductEnt["new_ticket"] = new EntityReference("new_pricingapprovalticket", TicketNumberId);
}
}
public Guid getTicketNumber(string ticketnumber, ref IOrganizationService service)
{
Guid TicketNumberGuid = Guid.Empty;
QueryExpression TicketNumberQuery = new QueryExpression { EntityName = "new_pricingapprovalticket", ColumnSet = new ColumnSet(true) };
TicketNumberQuery.Criteria.AddCondition("new_ticketnumber", ConditionOperator.Equal, ticketnumber);
EntityCollection TicketNumberQueryRetrieve = service.RetrieveMultiple(TicketNumberQuery);
for (var i = 0; i <TicketNumberQueryRetrieve.Entities.Count; i++)
{
TicketNumberGuid = TicketNumberQueryRetrieve.Entities[0].GetAttributeValue<Guid>("new_ticket");
}
return TicketNumberGuid;
}
当我启动 SSIS 包时,它运行没有错误。但不知何故,没有插入数据。
创建普通文本字段没有问题。但是当涉及到查找字段时,互联网解决方案建议根据我的代码使用EntityReference,但我不知道出了什么问题。所以我在这里有点迷失了。