Dynamics CRM中的注释(Note)及RollupRequest消息初探




我们把这FetchXML下载下来,增加几个显示的字段,用代码执行以下看看:
class Program
{
static void Main(string[] args)
{
var service = GetOrganizationService();
var fetchXML = string.Format(@"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>
<entity name='annotation'>
<attribute name='subject' />
<attribute name='notetext' />
<attribute name='filename' />
<attribute name='mimetype' />
<attribute name='isdocument' />
<attribute name='ownerid' />
<attribute name='annotationid' />
<order descending='false' attribute='subject' />
<link-entity name='account' to='objectid' from='accountid' alias='ac'>
<filter type='and'>
<condition value='A. Datum%' attribute='name' operator='like' />
</filter>
</link-entity>
</entity>
</fetch>");
EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchXML));
Console.WriteLine("名称以A. Datum开头的客户的注释信息:");
var i = ;
foreach (var entity in service.RetrieveMultiple(new FetchExpression(fetchXML)).Entities)
{
Console.WriteLine("第" + i + "个注释:");
Console.WriteLine("注释主题:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("注释内容:" + entity.GetAttributeValue<string>("notetext"));
Console.WriteLine("附件文件名称:" + entity.GetAttributeValue<string>("filename"));
Console.WriteLine("附件文件MIME类型:" + entity.GetAttributeValue<string>("mimetype"));
Console.WriteLine("注释是否包含附件:" + (entity.GetAttributeValue<bool>("isdocument")?"是":"否"));
Console.WriteLine("注释ID:" + entity.GetAttributeValue<Guid>("annotationid"));
Console.WriteLine("注释负责人:" + entity.GetAttributeValue<EntityReference>("ownerid").Name);
Console.WriteLine("--------------------------------------------------");
i++;
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}

static void Main(string[] args)
{
var service = GetOrganizationService();
var annotationEntity = new Entity("annotation");
//新增带不带附件的注释
annotationEntity["subject"] = "微软MVP罗勇用代码增加的不带附件的注释标题";
annotationEntity["notetext"] = "微软MVP罗勇用代码增加的不带附件的注释内容";
annotationEntity["isdocument"] = false;
annotationEntity["objectid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
service.Create(annotationEntity);
//新增带附件的注释
annotationEntity = new Entity("annotation");
annotationEntity["subject"] = "微软MVP罗勇用代码增加的带附件的注释标题";
annotationEntity["notetext"] = "微软MVP罗勇用代码增加的带附件的注释内容";
annotationEntity["filename"] = "sugege.png";
using (FileStream fs = File.OpenRead(@"D:\sugege.png"))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , bytes.Length);
annotationEntity["documentbody"] = Convert.ToBase64String(bytes);
}
annotationEntity["mimetype"] = "image/png";
annotationEntity["isdocument"] = true;
annotationEntity["objectid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
service.Create(annotationEntity);
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}

这个实体还支持消息RollupRequest,英文版的解释是:Retrieves the annotations (notes) related to the specified record (account, contact, or opportunity). 中文大概意思获取某条记录(仅支持客户,联系人,商机实体)相关的注释。如果不做实验的话,你可能会不明白这个相关到底是啥意思吧?我们用代码来看看:
static void Main(string[] args)
{
var service = GetOrganizationService();
var annotationEntity = new Entity("annotation");
RollupRequest rollupreq = new RollupRequest();
QueryExpression qe = new QueryExpression();
qe.EntityName = "annotation";
qe.ColumnSet = new ColumnSet("subject","notetext","createdon","objectid");
qe.Distinct = false;
qe.NoLock = true;
qe.AddOrder("createdon", OrderType.Ascending);
qe.Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("subject", ConditionOperator.NotNull)
},
};
rollupreq.Query = qe;
rollupreq.Target = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
rollupreq.RollupType = RollupType.Extended;
RollupResponse rollupResponse = (RollupResponse)service.Execute(rollupreq);
var i = ;
foreach (var entity in rollupResponse.EntityCollection.Entities)
{
Console.WriteLine("第" + (i+) + "个注释:");
Console.WriteLine("注释主题:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("注释内容:" + entity.GetAttributeValue<string>("notetext"));
Console.WriteLine("创建时间:" + entity.GetAttributeValue<DateTime>("createdon"));
//objectid字段不能获取它的Name属性,囧
Console.WriteLine("是关于实体:" + entity.GetAttributeValue<EntityReference>("objectid").LogicalName + "的记录:" + entity.GetAttributeValue<EntityReference>("objectid").Id);
i++;
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}

当然为了上面的代码更加好看到效果,我通过 客户的 上级单位 字段为目标客户建立了如下的层级关系:

Dynamics CRM中的注释(Note)及RollupRequest消息初探的更多相关文章
- 在Dynamics CRM中使用Bootstrap
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- Dyanmics CRM您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
当在操作CRM时,做不论什么的写操作包含创建数据.更新数据.都会提示以下截图中的错误:"您无法登陆系统.原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已 ...
- Dynamics CRM中一个查找字段引发的【血案】
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复267或者20180311可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
- 在Dynamics CRM中自定义一个通用的查看编辑注释页面
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复162或者20151016可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释在CRM中的显示是比较特别, ...
- Dynamics CRM中的操作(action)是否是一个事务(transaction)?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复168或者20151104可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 以前的博文 微软Dynamics ...
- Dynamics CRM中的地址知多D?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复169或者20151105可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! CRM中的地址以前不是很了解,定 ...
- Dynamics CRM 中Web API中的深度创建(Deep Insert)
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
问题发生在CRM 4.0 上 1 用户所在办事处及办事处上级被禁用. 2 如果已经重新启用了,还是报这个错误. 可以把停用的办事处及相关下级再重新--停用--启用一次试试. 3 如果还是报错,查看是否 ...
- Dynamics 365中的常用Associate和Disassociate消息汇总
摘要: 微软动态CRM专家罗勇 ,回复301或者20190123可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 因为编程时候 ...
随机推荐
- spark log4j 日志配置
现在我们介绍spark (streaming) job独立配置的log4j的方法,通过查看官方文档,要为应用主程序(即driver端)或执行程序使(即executor端)自定义log4j配置,需要两步 ...
- Access Editor Settings 访问编辑器设置
This topic demonstrates how to access editors in a Detail View using a View Controller. This Control ...
- 【koa2】用户注册、登录校验与加盐加密
加密与解密 先介绍一下关于服务端用户名跟密码的存储状态,我们知道当前端在注册一个新用户时,会在表单内填入用户名和密码,并通过post请求提交到服务器,服务器再把用户名和密码从ctx.request.b ...
- Linux安装docker-compose
下载:curl -L https://get.daocloud.io/docker/compose/releases/download/1.16.1/docker-compose-`uname -s` ...
- Kafka与RabbitMQ对比
Infi-chu: http://www.cnblogs.com/Infi-chu/ Kafka是LinkedIn在2012年发布的开源的消息发布订阅系统,他主要用于处理活跃的流式数据.大数据量的数据 ...
- ORACLE DATAGUARD 日志传输状态监控
ORACLE DATAGUARD的主备库同步,主要是依靠日志传输到备库,备库应用日志或归档来实现.当主.备库间日志传输出现GAP,备库将不再与主库同步.因此需对日志传输状态进行监控,确保主.备库间日志 ...
- [Go] 时序数据库influxdb的安装
日志类的数据时候存储在时序数据库中,下面就是时序数据库influxdb的安装 curl -sL https://repos.influxdata.com/influxdb.key | apt-key ...
- python xlwt写入excel操作
引用https://www.cnblogs.com/python-robot/p/9958352.html 安装 $ pip install xlwt 例子: import xlwt # 创建一个wo ...
- 对java的几点个人浅浅的认知
特点 简单地说,Java 具有如下特点:简单的.面向对象.平台无关.多线程.分布式.安全. 高性能.可靠的.解释型.自动垃圾回收等特点. 主要面向internet的语言 Java比其他任何一门语言 ...
- 设计模式-Strategy Strategy将算法封装到类中,通过组合的方式 将具体算法的实现在组合对象中实现
以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //strategy.h #pragma once class Strategy { public: Strategy(); ...