代码之家  ›  专栏  ›  技术社区  ›  aminvincent

使用C从CRM 365中的查找中动态获取值#

  •  0
  • aminvincent  · 技术社区  · 7 年前

    我有一个实体“new\u trialxrmservicetoolkit”,里面有一个查找字段“new\u LookupTransactionHeader”,它链接到“new\u transactionheader”实体。

    如何解决这个问题?

    我明白了 tutorial

    我的代码:

    new_trialxrmservicetoolkit t = new new_trialxrmservicetoolkit();
    
    ColumnSet myAttributes = new ColumnSet(new String[] { "new_LookupTransactionHeader" });
    Entity myEntityHavingLookup = service.Retrieve("new_transactionheader", t.id, myAttributes);
    var myLookupId = ((Microsoft.Xrm.Sdk.EntityReference)(myEntityHavingLookup.Attributes["new_LookupTransactionHeader"])).Id;
    
    throw new InvalidPluginExecutionException(myLookupId.ToString()); // catch this result
    

    这是我测试插件时的结果: enter image description here

    3 回复  |  直到 7 年前
        1
  •  1
  •   Ranjith Balmoori    7 年前

    这段代码是在为'

    var entity = (Entity)context.InputParameters["Target"];
    if (entity.LogicalName != "new_trialxrmservicetoolkit")
        return;
    var entityId=  entity.Id;
    ColumnSet myAttributes = new ColumnSet(new String[] { "new_LookupTransactionHeader" });
    Entity myEntityHavingLookup = service.Retrieve("new_trialxrmservicetoolkit", entityId, myAttributes);
    var myLookupId = ((Microsoft.Xrm.Sdk.EntityReference)(myEntityHavingLookup.Attributes["new_LookupTransactionHeader"])).Id;
    throw new InvalidPluginExecutionException(myLookupId.ToString());
    

    如果插件用于“删除”消息,请更改我代码的第一行:

    var entity = (EntityReference)context.InputParameters["Target"];
    
        2
  •  0
  •   Arun Vinoth PrecogTechnologies    7 年前

    t 属于类型 new_trialxrmservicetoolkit t.id 对于 new_LookupTransactionHeader 类型

    targetentity

        3
  •  -1
  •   Tha'er AlAjlouni ثائر العجلوني    6 年前

    获取查找字段的值

    EntityReference entref = (EntityReference)item.Attributes[attributeName];
    
    var LookupId = entref.Id;
    
    var logicalName = entref.LogicalName;
    

    设置查找字段的值

    newAccount[attributeName] = new EntityReference(logicalName, LookupId);
    

    newAccount[attributeName] = Null;