【问题标题】:how to populate multiple line textbox in crm using plugin如何使用插件在 crm 中填充多行文本框
【发布时间】:2017-10-08 09:35:49
【问题描述】:

嘿,我想知道通过插件填充多行字段的方法是什么,我需要在多行字段中开始一个新行。 我的代码是:

 foreach (Entity ent in allMyEnts.Entities)
          {            
                 //base_filesName is the multiple field need to be filled 
                 //inside my loop                                                  
             entityHoldsMultipleLineField.base_filesName =ent.base_name;
                                       }

或者我应该创建一个数组并使用循环填充我的字段? 最好的方法是什么?

【问题讨论】:

    标签: c# plugins dynamics-crm-2013


    【解决方案1】:

    首先,您的代码中存在Entity ent 的错误,因为您随后引用了ent.base_name - 这不起作用,因为您将对象称为早期绑定实体,但您将其转换为晚期 -绑定在foreach 语句中。我将假设您打算使用后期绑定作为我的答案(您可以根据需要将其更改为早期绑定。

    就 Dynamics 和 .NET 而言,多行文本框仍然是 string。您可以使用StringBuilder 类轻松创建多行字符串,然后将生成的string(通过.ToString())添加到正确的字段中。

    var multiLineStringResult = new StringBuilder();
    
    foreach (Entity ent in allMyEnts.Entities)
    {
        //base_filesName is the multiple field need to be filled 
        //inside my loop                                                  
         multiLineStringResult.AppendLine(ent.GetAttributeValue<string>("base_name"));
    }
    
    entityHoldsMultipleLineField["base_filesName"] = multiLineStringResult.ToString(); 
    

    【讨论】:

    • 你说得对,crm 多行没有特殊的属性,最后我使用了简单的:{entityHoldsMultipleLineField.base_filesName =ent.base_name + Environment.NewLine;} 就是这样:)
    猜你喜欢
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多