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

时间:2017-10-08 09:35:50

标签: c# plugins dynamics-crm-2013

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

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

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

1 个答案:

答案 0 :(得分: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();