簡體   English   中英

如何使用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中的名稱字段是文本字段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 keyUpsertRequest僅適用於Dynamics 365(在線),Dynamics 365(本地),Dynamics CRM 2016,Dynamics CRM Online。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM