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 . 因为编程时候 ...
随机推荐
- C# 重置IE安全等级
打开IE设置-安全 dynamic shellObject = Interaction.CreateObject("WScript.Shell", ""); / ...
- Web 安全总结
同源策略 如果两个 URL 的协议.域名和端口都相同,我们就称这两个 URL 同源. 同源策略限制了来自不同源的 JavaScript 脚本对当前 DOM 对象读和写的操作. 同源策略限制了不同源的站 ...
- Cesium专栏-克里金插值(全国温度为例,附源码下载)
Cesium Cesium 是一款面向三维地球和地图的,世界级的JavaScript开源产品.它提供了基于JavaScript语言的开发包,方便用户快速搭建一款零插件的虚拟地球Web应用,并在性能,精 ...
- 【Gradle】Android Gradle 插件
Android Gradle 插件 Android Gradle 插件简介 从Gradle角度来看,Android其实是Gradle的一个第三方插件,它是由Google的Android团队开发的.但从 ...
- CodeForces 1238C(思维+贪心)
题意 https://vjudge.net/problem/CodeForces-1238C 您现在正在玩一个游戏,您初始在一个高度 h 的悬崖 悬崖沿壁高度为 1-h 的这些位置均有平台,平台有两种 ...
- java8-12-Optional类
Optional类 java.util.Optional 是一个容器类 避免空指针 NPE 能够快速定位空指针 常用方法: Optional.of(T t) : 创建一个 Optio ...
- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
传送门 A. Optimal Currency Exchange 枚举一下就行了. Code #include <bits/stdc++.h> using namespace std; t ...
- 物理像素[设备像素] & 逻辑像素[CSS像素];
为什么移动端CSS里面写了1px,实际上看起来比1px粗 了解设备物理像素和逻辑像素的同学应该很容易理解,其实这两个px的含义其实是不一样的, UI设计师要求的1px是指设备的物理像素1px,而CSS ...
- LINUX上安装JDK+tomcat+mysql操作笔记
1.环境准备: 1-1.centos 64位(本人的虚拟机安装此系统),安装步骤和网络配置已经在前两篇记录. 1-2.JDK 版本1.8 1-3.tomcat压缩包 1-4.CRT远程连接工具(可用其 ...
- WPF 精修篇 DataGrid 数据源排序
原文:WPF 精修篇 DataGrid 数据源排序 效果 <DataGrid x:Name="datagrid" ItemsSource="{Binding Ele ...