C# 如何使用插件在crm中填充多行文本框
嘿,我想知道通过插件填充多行字段的方法是什么,我需要在多行字段中开始一个新行。 我的代码是:C# 如何使用插件在crm中填充多行文本框,c#,plugins,dynamics-crm-2013,C#,Plugins,Dynamics Crm 2013,嘿,我想知道通过插件填充多行字段的方法是什么,我需要在多行字段中开始一个新行。 我的代码是: foreach (Entity ent in allMyEnts.Entities) { //base_filesName is the multiple field need to be filled //inside my loop
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;
}
或者我应该创建一个数组并用循环填充我的字段?
最好的方法是什么?首先,您的
实体ent
代码中有一个bug,因为您随后引用了ent.base\u name
-这不起作用,因为您将对象作为早期绑定的实体调用,但在foreach
语句中将其强制转换为晚期绑定。我将假设您打算在我的答案中使用延迟绑定(您可以根据需要将其更改为提前绑定)
就Dynamics和.NET而言,多行文本框仍然是一个字符串
。您可以使用StringBuilder
类轻松创建多行字符串,然后将生成的字符串
(通过.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();
var multileStringResult=new StringBuilder();
foreach(allMyEnts.Entities中的实体ent)
{
//base_filename是需要填写的多个字段
//在我的圈子里
multileStringResult.AppendLine(ent.GetAttributeValue(“base_name”);
}
entityHoldsMultipleLineField[“基本文件名”]=multiLineStringResult.ToString();
你说得对crm multiline没有特殊属性,最后我使用了简单的:{entityHoldsMultipleLineField.base\u filename=ent.base\u name+Environment.NewLine;}仅此而已:)