CRM2011 添加按钮到subgrid的ribbon上
添加按钮到subgrid的ribbon上,并定义点击按钮执行的命令。
继续阅读 »
[CRM2011 javascript] Get entity id and run workflow
取得当前Form的entity id并执行workflow。
继续阅读 »
七宗罪 by Blackeri
此文目的在于记几个单词,欣赏几张插画。
这七宗罪,每个人或多或少都会有吧,
七宗罪:
Avarice(贪婪),Envy(嫉妒),Gluttony(饕餮),Lust(淫欲),Sloth(懒惰),Vanity(傲慢),Wrath(暴怒)
MSCRM4.0 交叉表查询
当两个实体是多对多的关系时,CRM会创建一个交叉表,查询这个交叉表的数据不能用RetrieveMultiple,而需要用Fecth方法。
如果你用RetrieveMultiple的话,会出现以下错误:
0×80040800
The ‘RetrieveMultiple’ method does not support entities of type ‘cust_list_cust_survey’.
Platform
怎样用Fecth方法呢?以下例子来自MSDN(Using Intersect Tables):
-
CrmAuthenticationToken token = new CrmAuthenticationToken();
-
token.AuthenticationType = 0;
-
token.OrganizationName = "AdventureWorksCycle";
-
-
CrmService service = new CrmService();
-
service.Url = ""http://:/mscrmservices/2007/crmservice.asmx";
-
service.CrmAuthenticationTokenValue = token;
-
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
-
-
// Get the GUID of the current user.
-
WhoAmIRequest who = new WhoAmIRequest();
-
WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(who);
-
-
Guid userid = whoResp.UserId;
-
-
// Create a query expression.
-
QueryExpression qe = new QueryExpression();
-
qe.EntityName = "role";
-
// Be aware that using AllColumns may adversely affect performance
-
// and cause unwanted cascading in subsequent updates.
-
// A best practice is to retrieve the least amount of data required.
-
qe.ColumnSet = new AllColumns();
-
-
// Create the link entity from role to systemuserroles.
-
LinkEntity le = new LinkEntity();
-
le.LinkFromEntityName = "role";
-
le.LinkFromAttributeName = "roleid";
-
le.LinkToEntityName = "systemuserroles";
-
le.LinkToAttributeName = "roleid";
-
-
LinkEntity le2 = new LinkEntity();
-
le2.LinkFromEntityName = "systemuserroles";
-
le2.LinkFromAttributeName = "systemuserid";
-
le2.LinkToEntityName = "systemuser";
-
le2.LinkToAttributeName = "systemuserid";
-
-
// Create the condition to test the user ID.
-
ConditionExpression ce = new ConditionExpression();
-
ce.AttributeName = "systemuserid";
-
ce.Operator = ConditionOperator.Equal;
-
ce.Values = new object[]{userid};
-
-
// Add the condition to the link entity.
-
le2.LinkCriteria = new FilterExpression();
-
le2.LinkCriteria.Conditions = new ConditionExpression[]{ce};
-
-
// Add the from and to links to the query.
-
le.LinkEntities = new LinkEntity[]{le2};
-
qe.LinkEntities = new LinkEntity[]{le};
-
-
// Retrieve the roles and write each one to the console.
-
BusinessEntityCollection bec = service.RetrieveMultiple(qe);
-
foreach (BusinessEntity e in bec.BusinessEntities)
-
{
-
role r = (role)e;
-
Console.WriteLine(r.name.ToString());
-
}
The FetchXML Wizard – 轻松生成CRM代码
-
INNER JOIN listmember ON listmember.entityid=lead.leadid
-
WHERE
-
listmember.listid='1E565422-A7AE-E011-958A-000C29295BC9'
-
AND lead.emailaddress1='test999@gmail.com'
以上语句转成c#代码是这个样子的:
-
-
QueryExpression query1 = new QueryExpression();
-
query1.EntityName = "lead";
-
ColumnSet columns1 = new ColumnSet();
-
columns1.Attributes = new string[] { "emailaddress1" };
-
query1.ColumnSet = columns1;
-
query1.Criteria = new FilterExpression();
-
query1.Criteria.FilterOperator = LogicalOperator.And;
-
query1.Criteria.Conditions = new ConditionExpression[] { condition1 };
-
-
LinkEntity linkEntityForLead = new LinkEntity();
-
linkEntityForLead.JoinOperator = JoinOperator.Natural;
-
linkEntityForLead.LinkFromEntityName = "lead";
-
linkEntityForLead.LinkFromAttributeName = "leadid";
-
linkEntityForLead.LinkToEntityName = "listmember";
-
linkEntityForLead.LinkToAttributeName = "entityid";
-
-
linkEntityForLead.LinkCriteria = new FilterExpression();
-
linkEntityForLead.LinkCriteria.FilterOperator = LogicalOperator.And;
-
-
linkEntity1.LinkCriteria.Conditions = new ConditionExpression[] { condition2 };
-
query1.LinkEntities = new LinkEntity[] { linkEntityForLead };
每次,当我写这些代码的时候,都很想死,同时觉得好爱sql哦。
今天我终于找到这么一个工具,可以直接生成c#代码!
那就是——The FetchXML Wizard(点击进入下载)
这个工具,只要输入CRM server的名字就可以了。然后根据需要选择相应的实体,条件,排序等等,好用极了。不知道我是不是out了今天才知道呃。。。
SQL批量插入数据的语句
菜鸟记录,高手无视。
-
DECLARE @MyCounter INT
-
-
SET @MyCounter = 0 /*设置变量*/
-
-
WHILE (@MyCounter < 2500) /*设置循环次数*/
-
-
BEGIN
-
-
-
-
/*这里是 insert 语句*/
-
-
-
-
SET @MyCounter = @MyCounter + 1
-
-
END
MSCRM4.0 用代码批量发送邮件
工作中的需求: 邮件的接收者是一个list,list中有2千多个邮件地址。
发送过程中遇到错误,只发出了大概1千个邮件。
是用代码来发送的,遇到的错误是:
“Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:80”
首先,以上错误可以通过Thread.sleep() 来避免,我的设置是Thread.sleep(50)。这么一来,上面的错误不再出现了,但是却出现了CRM超时的错误。
好吧,既然这样,我只好延长一下CRM超时时间了。
进到管理工具 – IIS管理:
点开Web Sites,右键点击Microsoft Dynamics CRM,选择属性(Properties),如下图:
然后选择ASP.NET 标签
点击Edit Configuration,然后在接下来的窗口选择Application标签,
设置超时时间。
然后就OK了。我设置1800秒,也就是半个小时,基本上可以满足发送5000封邮件的需要了。
慎选团购图片——新加坡团购网站质量分析
多年前,我曾当过淘宝店主,那时我就琢磨出来了,网上购物看不见摸不着实物,照片的作用很关键。同样的东西,一个图片好看,另一个图片难看,肯定是图片好看那个卖得好。
现在,团购大战在新加坡打得火热,我每天在iLoveDeals.SG新加坡团购导航网站上看到许许多多的团购信息,有的时候真的有种看不下去的感觉——有些个团购网站选的图片简直惨不忍睹。
团购图片最重要的是:一目了然和吸引人。
首先图片必须让人一看就知道是什么东西,明白这个团购的对象是什么,你不能搞个美食的团购,然后放个美女的图片。
其次,图片必须吸引人,有时候商家提供的图片不太好看,团购网站可以对图片进行美化或者找类似的图片来代替。
俗话说——无图无真相。下面我们就来——看图说话。
1. 食物类。
其实,很多食物本身好吃,但是看起来不是那么美的。但是消费者在电脑前尝不到也闻不到,只能靠图片来感受。所以不管怎样,食物的图片不经美化就放上来绝对是很笨的做法。
下面这张图片如果谁会有一点食欲,我就服了! 继续阅读 »
MSCRM4.0 检查用户访问权限(RetrievePrincipalAccessResponse)
工作中经常遇到某个用户在CRM里不能创建或修改某些记录。这通常是因为这个用户对要修改的这个实体没有权限或者权限不足。
如果在用户没有权限的情况下允许其对记录进行提交,可能会引起一系列问题。所以最好是在用户试图修改这些他没有权限的实体之前就通知他,避免他进行下一步操作。
那么如何检查呢?
下面引用MSCRM4.0 SDK的例子:
Example
The following code example shows how to use the RetrievePrincipalAccess message.
[C#]
-
// Set up the CRM service.
-
CrmAuthenticationToken token = new CrmAuthenticationToken();
-
// You can use enums.cs from the SDK\Helpers folder to get the enumeration
-
// for Active Directory authentication.
-
token.AuthenticationType = 0;
-
token.OrganizationName = "AdventureWorksCycle";
-
-
CrmService service = new CrmService();
-
service.Url =
-
"http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
-
service.CrmAuthenticationTokenValue = token;
-
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
-
-
// Create the SecurityPrincipal object.
-
//创建需要检查的用户对象
-
// This references the user whose access is being checked.
-
SecurityPrincipal principal = new SecurityPrincipal();
-
-
// Set the properties of th SecurityPrincipal object.
-
//说明用户在CRM中的类型
-
// Type is the typecode of the principalid.
-
principal.Type = SecurityPrincipalType.User;
-
// PrincipalId is the GUID of the user whose access is being checked.
-
//用户的GUID
-
principal.PrincipalId =
-
new Guid("F111F0B1-70CE-44B4-8BF2-2E6C7EADA111");
-
-
// Create the target for the request.
-
//创建要检查的实体,这里以Account为例
-
TargetOwnedAccount owner = new TargetOwnedAccount();
-
-
// EntityId is the GUID of the account to which access is being checked.
-
//实体的GUID,也就是指明具体要检查哪一个实体对象
-
owner.EntityId =
-
new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
-
-
// Create the request object. 创建请求对象
-
RetrievePrincipalAccessRequest access =
-
new RetrievePrincipalAccessRequest();
-
-
// Set the properties of the request object.
-
access.Principal = principal;
-
access.Target = owner;
-
-
// Execute the request. 执行请求
-
//如果用户没有任何权限访问该实体,这里会抛出异常。
-
//我们的程序中需要对该异常进行处理,比如通知用户这个异常。
-
//注意,只要用户有访问权限这里就不会抛出异常,所以对于权限不足的情况需要特殊处理。
-
RetrievePrincipalAccessResponse accessResponse =
-
(RetrievePrincipalAccessResponse)service.Execute(access);
RetrievePrincipalAccessResponse有一个属性:AccessRights
这里返回当前用户对这个实体具有的所有权限,比如:
AppendAccess,AssignAccess,CreateAccess,DeleteAccess,ReadAccess等等。






