如何使用插件在crm中填充多行文本框

how to populate multiple line textbox in crm using plugin

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

 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;
                                       }

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

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

就 Dynamics 和 .NET 而言,多行文本框仍然是 string。您可以使用 StringBuilder class 轻松创建多行字符串,然后将结果 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();