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 . 因为编程时候 ...
随机推荐
- 用 Python 实现植物大战僵尸代码!
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: marble_xu GitHub地址:https://github ...
- 本地SQL Server数据库提示网络问题无法连接
运行程序时发现本地SQLserver数据库无法连接,提示信息为:在与SQL Server 建立连接时出现与网络相关的或特定与实例的错误.未能找到或无法访问服务器.请验证实例名称是否正确并且SQL Se ...
- C#中在多个地方调用同一个触发器从而触发同一个自定义委托的事件
场景 在Winfom中可以在页面上多个按钮或者右键的点击事件中触发同一个自定义的委托事件. 实现 在位置一按钮点击事件中触发 string parentPath = System.IO.Directo ...
- RDIFramework.NET敏捷开发框架 ━ 工作流程组件Web业务平台
接前两篇: RDIFramework.NET敏捷开发框架 ━ 工作流程组件介绍 RDIFramework.NET敏捷开发框架 ━ 工作流程组件WinForm业务平台 1.RDIFramework.NE ...
- springboot进入html
话不多说,转载 https://blog.csdn.net/sinat_33889619/article/details/78339042 这个博客写的真好
- 执行 Run manage.py Task 报 AttributeError: 'Command' object has no attribute 'usage'?
这个问题,是python与Pycharm不兼容导致,解决办法将Pycharm升级最新版本
- cf之kmp匹配稍稍改一改
看样例就知道要干嘛了 http://codeforces.com/contest/1200/problem/E 每次我们用新的串和答案串匹配,答案串的匹配位置是max(0,(int)ans.size( ...
- LG3092 「USACO2013NOV」No Change 状压DP
问题描述 https://www.luogu.org/problem/P3092 题解 观察到 \(k \le 16\) ,自然想到对 \(k\) 状压. 设 \(opt[i]\) 代表使用硬币状况为 ...
- [CF1082D]Maximum Diameter Graph
题目描述 Description Graph constructive problems are back! This time the graph you are asked to build sh ...
- 趣谈Linux操作系统学习笔记:第二十讲
一.引子 1.计算两方面的原因 2.内存管理机制 二.独享内存空间的原理 1.会议室和物理内存的关系 和会议室一样,内存都被分成一块块儿的,都编号了号,例如3F-10就是三楼十号会议室.内存页有这样一 ...