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 . 因为编程时候 ...
随机推荐
- 假设高度已知,请写出三栏布局,其中左右各为300px 中间自适用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在vue中添加ico图标
准备:添加 ico图标在与index.html同级的目录 第一种方法: 在index.html中引入: <link rel="shortcuticon" type=" ...
- ES6-Set的增加、查找、删除、遍历、查看长度、数组去重
set 是es6新出的一种数据结构,里边放的是数组. 作用:去重(set里边的数组不能重复) MDN:Set 对象允许你存储任何类型的唯一值,无论是原始值或者是对象引用. 总结: 1.成员唯一.无序且 ...
- GPS NMEA-0183协议常用报文数据格式
点击上方↑↑↑蓝字[协议分析与还原]关注我们 " 整理的GPS有关的协议分析资料." 之前分析一些车载设备的流量时,有部分经验,在这里和大家分享. 产生这些流量的设备通常是实体终端 ...
- Nginx web基础入门
目录 Nginx web基础入门 如何升级nginx或者添加功能 使用systemd管理nginx nginx相关配置文件 nginx的配置文件详解 日志格式 game日志记录实战 日志切割 手写虚拟 ...
- bay——巡检RAC命令_版本.txt
df -lhhostnamecat /etc/hostsifconfig ps -ef | grep tnsps -ef | grep asmps -ef | grep ora_ ls -l /dev ...
- 工作日志,证书无效 unable to find valid certification path to requested target
工作日志,证书无效 unable to find valid certification path to requested target 最近被这个问题弄得头大.导致所有用到 se.transmod ...
- 渗透测试学习 二十九、kali安装,信息搜集,服务器扫描
kali安装,信息搜集,服务器扫描 kali介绍 Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统.由Offensive Security Ltd维护和资助.最先由 ...
- centos 6.9 升级glibc动态库
glibc是gnu发布的libc库,即c运行库,glibc是linux系统中最底层的api,几乎其它任何运行库都会依赖于glibc.glibc除了封装linux操作系统所提供的系统服务外,它本身也提供 ...
- 飞思卡尔K60时钟分析
推荐:NXP官方软件config tool,图形化界面可导出代码 K60芯片的时钟系统由振荡器(OSC).实时振荡器(RTC OSC).多功能时钟发生器(MCG).系统集成模块(SIM)和电源管理器( ...