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 . 因为编程时候 ...
随机推荐
- 工作总结汇报公司介绍产品宣传品牌展示企业文化PPT模
清晰明了:在工作总结会议上都是要严肃为主,搞的花里胡哨既不好看也让领导有不好的影响:微粒体:模板样式立体效果非常好,能够一把将观众眼球给吸引住:样式齐全:各种PPT样式都有,能够承载工作汇报各种内容: ...
- Swift实战技巧
Swift实战技巧 从OC转战到Swift,差别还是蛮大的,本文记录了我再从OC转到Swift开发过程中遇到的一些问题,然后把我遇到的这些问题记录形成文章,大体上是一些Swift语言下面的一些技巧,希 ...
- sched_yield()和nanosleep()对进程调度的影响
关键词:sched_yield().nanosleep()等等. sched_yield()主动放弃CPU执行权,nanosleep()是睡眠一段时间后再唤醒. 1. sched_yield()实现 ...
- Golang防止多个进程重复执行
创建锁文件 lockFile := "./lock.pid" lock, err := os.Create(lockFile) if err != nil { log.Fatal( ...
- CodeForces - 722C(思维+倒着并查集)
题意 https://vjudge.net/problem/CodeForces-722C 给你一个由n个非负整数组成的数列 a1 ,a2 ,...,an . 你将要一个一个摧毁这个数列中的数. ...
- Shadow Map(单方向)
很早就想看阴影映射,一直拖到了现在,今天终于看了单方向的阴影映射,然后搭了个场景看了一下效果(每次搭场景感觉有点麻烦). 阴影映射的大体过程: // 1. 首选渲染深度贴图 glViewport(, ...
- java8-02-再探Lambda表达式
Lambda表达式 主要作用替代匿名内部类 达到简化代码的操作 Lambda表达式 在对象中的使用 Employee类
- MongoDB学习笔记(二、MongoDB查询)
目录: MongoDB数据类型 MongoDB新增语法 MongoDB查询语法 MongoDB查询选择器 MongoDB关联查询 MongoDB数据类型: MongoDB新增语法: 语法:db.col ...
- ACWING 844. 走迷宫
地址 https://www.acwing.com/problem/content/description/846/ 给定一个n*m的二维整数数组,用来表示一个迷宫,数组中只包含0或1,其中0表示可以 ...
- mysql深入学习(一)
Mysql高级学习 一.Mysql简介 1.概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL是一种关联数据库管理系统,将数据保存在不同 ...