CRM2011 添加按钮到subgrid的ribbon上

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/31,17:08 | 5条评论

添加按钮到subgrid的ribbon上,并定义点击按钮执行的命令。
继续阅读 »

[CRM2011 javascript] Get entity id and run workflow

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/31,17:01 | 没有评论

取得当前Form的entity id并执行workflow。
继续阅读 »

再爬武吉知马

Joy 分类:生活点滴 | Joy 标签: Joy 发表于2011/07/24,18:48 | 19条评论

几个月前,曾和LBY去了一次武吉知马,那时在山上见了很多猴子。今天再去,猴子竟没见几只,大概是吃饱了都躲起来睡觉了。

很久没锻炼,开始爬山的时候真的很喘,开始的这一段很陡。

这座山很矮,基本上爬过了开始那段陡坡,后面就没什么挑战性了。我们选择的是中等难度的路线,不一会儿就到顶峰小屋了。在那里终于看到一只猴子。 继续阅读 »

七宗罪 by Blackeri

Joy 分类:乱七八糟 | Joy 标签:Joy 发表于2011/07/22,23:40 | 11条评论

此文目的在于记几个单词,欣赏几张插画。

这七宗罪,每个人或多或少都会有吧,

七宗罪:

Avarice(贪婪),Envy(嫉妒),Gluttony(饕餮),Lust(淫欲),Sloth(懒惰),Vanity(傲慢),Wrath(暴怒)

Avarice

Picture 1 of 7

MSCRM4.0 交叉表查询

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/20,20:50 | 6条评论

当两个实体是多对多的关系时,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):

// Set up the CRM Service.
  1. CrmAuthenticationToken token = new CrmAuthenticationToken();
  2. token.AuthenticationType = 0;
  3. token.OrganizationName = "AdventureWorksCycle";
  4.  
  5. CrmService service = new CrmService();
  6. service.Url = ""http://:/mscrmservices/2007/crmservice.asmx";
  7. service.CrmAuthenticationTokenValue = token;
  8. service.Credentials = System.Net.CredentialCache.DefaultCredentials;
  9.  
  10. // Get the GUID of the current user.
  11. WhoAmIRequest who = new WhoAmIRequest();
  12. WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(who);
  13.  
  14. Guid userid = whoResp.UserId;
  15.  
  16. // Create a query expression.
  17. QueryExpression qe = new QueryExpression();
  18. qe.EntityName = "role";
  19. // Be aware that using AllColumns may adversely affect performance
  20. // and cause unwanted cascading in subsequent updates.
  21. // A best practice is to retrieve the least amount of data required.
  22. qe.ColumnSet = new AllColumns();
  23.  
  24. // Create the link entity from role to systemuserroles.
  25. LinkEntity le = new LinkEntity();
  26. le.LinkFromEntityName = "role";
  27. le.LinkFromAttributeName = "roleid";
  28. le.LinkToEntityName = "systemuserroles";
  29. le.LinkToAttributeName = "roleid";
  30.  
  31. LinkEntity le2 = new LinkEntity();
  32. le2.LinkFromEntityName = "systemuserroles";
  33. le2.LinkFromAttributeName = "systemuserid";
  34. le2.LinkToEntityName = "systemuser";
  35. le2.LinkToAttributeName = "systemuserid";
  36.  
  37. // Create the condition to test the user ID.
  38. ConditionExpression ce = new ConditionExpression();
  39. ce.AttributeName = "systemuserid";
  40. ce.Operator = ConditionOperator.Equal;
  41. ce.Values = new object[]{userid};
  42.  
  43. // Add the condition to the link entity.
  44. le2.LinkCriteria = new FilterExpression();
  45. le2.LinkCriteria.Conditions = new ConditionExpression[]{ce};
  46.  
  47. // Add the from and to links to the query.
  48. le.LinkEntities = new LinkEntity[]{le2};
  49. qe.LinkEntities = new LinkEntity[]{le};
  50.  
  51. // Retrieve the roles and write each one to the console.
  52. BusinessEntityCollection bec = service.RetrieveMultiple(qe);
  53. foreach (BusinessEntity e in bec.BusinessEntities)
  54. {
  55.    role r = (role)e;
  56.    Console.WriteLine(r.name.ToString());
  57. }

The FetchXML Wizard – 轻松生成CRM代码

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/20,20:41 | 2条评论
select * from lead
  1. INNER JOIN listmember ON listmember.entityid=lead.leadid
  2. WHERE
  3. listmember.listid='1E565422-A7AE-E011-958A-000C29295BC9'
  4. AND lead.emailaddress1='test999@gmail.com'

以上语句转成c#代码是这个样子的:

  1.  
  2. QueryExpression query1 = new QueryExpression();
  3. query1.EntityName = "lead";
  4. ColumnSet columns1 = new ColumnSet();
  5. columns1.Attributes = new string[] { "emailaddress1" };
  6. query1.ColumnSet = columns1;
  7. query1.Criteria = new FilterExpression();
  8. query1.Criteria.FilterOperator = LogicalOperator.And;
  9. query1.Criteria.Conditions = new ConditionExpression[] { condition1 };
  10.  
  11. LinkEntity linkEntityForLead = new LinkEntity();
  12. linkEntityForLead.JoinOperator = JoinOperator.Natural;
  13. linkEntityForLead.LinkFromEntityName = "lead";
  14. linkEntityForLead.LinkFromAttributeName = "leadid";
  15. linkEntityForLead.LinkToEntityName = "listmember";
  16. linkEntityForLead.LinkToAttributeName = "entityid";
  17.  
  18. linkEntityForLead.LinkCriteria = new FilterExpression();
  19. linkEntityForLead.LinkCriteria.FilterOperator = LogicalOperator.And;
  20.  
  21. linkEntity1.LinkCriteria.Conditions = new ConditionExpression[] { condition2 };
  22. query1.LinkEntities = new LinkEntity[] { linkEntityForLead };

每次,当我写这些代码的时候,都很想死,同时觉得好爱sql哦。

今天我终于找到这么一个工具,可以直接生成c#代码!

那就是——The FetchXML Wizard(点击进入下载

这个工具,只要输入CRM server的名字就可以了。然后根据需要选择相应的实体,条件,排序等等,好用极了。不知道我是不是out了今天才知道呃。。。

SQL批量插入数据的语句

Joy 分类:好好学习 | Joy 标签:Joy 发表于2011/07/16,23:54 | 5条评论

菜鸟记录,高手无视。

  1. DECLARE @MyCounter INT
  2.  
  3. SET @MyCounter = 0            /*设置变量*/
  4.  
  5. WHILE (@MyCounter < 2500)     /*设置循环次数*/
  6.  
  7. BEGIN
  8.  
  9.  
  10.  
  11. /*这里是 insert 语句*/
  12.  
  13.  
  14.  
  15. SET @MyCounter = @MyCounter + 1
  16.  
  17. END

MSCRM4.0 用代码批量发送邮件

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/15,23:29 | 4条评论

工作中的需求: 邮件的接收者是一个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封邮件的需要了。

 

慎选团购图片——新加坡团购网站质量分析

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/03,18:56 | 20条评论

多年前,我曾当过淘宝店主,那时我就琢磨出来了,网上购物看不见摸不着实物,照片的作用很关键。同样的东西,一个图片好看,另一个图片难看,肯定是图片好看那个卖得好。

现在,团购大战在新加坡打得火热,我每天在iLoveDeals.SG新加坡团购导航网站上看到许许多多的团购信息,有的时候真的有种看不下去的感觉——有些个团购网站选的图片简直惨不忍睹。

团购图片最重要的是:一目了然和吸引人。

首先图片必须让人一看就知道是什么东西,明白这个团购的对象是什么,你不能搞个美食的团购,然后放个美女的图片。

其次,图片必须吸引人,有时候商家提供的图片不太好看,团购网站可以对图片进行美化或者找类似的图片来代替。

俗话说——无图无真相。下面我们就来——看图说话。

1. 食物类。

其实,很多食物本身好吃,但是看起来不是那么美的。但是消费者在电脑前尝不到也闻不到,只能靠图片来感受。所以不管怎样,食物的图片不经美化就放上来绝对是很笨的做法。

下面这张图片如果谁会有一点食欲,我就服了! 继续阅读 »

MSCRM4.0 检查用户访问权限(RetrievePrincipalAccessResponse)

Joy 分类:好好学习 | Joy 标签: Joy 发表于2011/07/01,16:04 | 5条评论

工作中经常遇到某个用户在CRM里不能创建或修改某些记录。这通常是因为这个用户对要修改的这个实体没有权限或者权限不足。

如果在用户没有权限的情况下允许其对记录进行提交,可能会引起一系列问题。所以最好是在用户试图修改这些他没有权限的实体之前就通知他,避免他进行下一步操作。

那么如何检查呢?

下面引用MSCRM4.0 SDK的例子:

Example

The following code example shows how to use the RetrievePrincipalAccess message.

[C#]

  1. // Set up the CRM service.
  2. CrmAuthenticationToken token = new CrmAuthenticationToken();
  3. // You can use enums.cs from the SDK\Helpers folder to get the enumeration
  4. // for Active Directory authentication.
  5. token.AuthenticationType = 0;
  6. token.OrganizationName = "AdventureWorksCycle";
  7.  
  8. CrmService service = new CrmService();
  9. service.Url =
  10.  "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
  11. service.CrmAuthenticationTokenValue = token;
  12. service.Credentials = System.Net.CredentialCache.DefaultCredentials;
  13.  
  14. // Create the SecurityPrincipal object.
  15. //创建需要检查的用户对象
  16. // This references the user whose access is being checked.
  17. SecurityPrincipal principal = new SecurityPrincipal();
  18.  
  19. // Set the properties of th SecurityPrincipal object.
  20. //说明用户在CRM中的类型
  21. // Type is the typecode of the principalid.
  22. principal.Type = SecurityPrincipalType.User;
  23. // PrincipalId is the GUID of the user whose access is being checked.
  24. //用户的GUID
  25. principal.PrincipalId =
  26.  new Guid("F111F0B1-70CE-44B4-8BF2-2E6C7EADA111");
  27.  
  28. // Create the target for the request.
  29. //创建要检查的实体,这里以Account为例
  30. TargetOwnedAccount owner = new TargetOwnedAccount();
  31.  
  32. // EntityId is the GUID of the account to which access is being checked.
  33. //实体的GUID,也就是指明具体要检查哪一个实体对象
  34. owner.EntityId =
  35.  new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
  36.  
  37. // Create the request object. 创建请求对象
  38. RetrievePrincipalAccessRequest access =
  39.  new RetrievePrincipalAccessRequest();
  40.  
  41. // Set the properties of the request object.
  42. access.Principal = principal;
  43. access.Target = owner;
  44.  
  45. // Execute the request. 执行请求
  46. //如果用户没有任何权限访问该实体,这里会抛出异常。
  47. //我们的程序中需要对该异常进行处理,比如通知用户这个异常。
  48. //注意,只要用户有访问权限这里就不会抛出异常,所以对于权限不足的情况需要特殊处理。
  49. RetrievePrincipalAccessResponse accessResponse =
  50.  (RetrievePrincipalAccessResponse)service.Execute(access);

RetrievePrincipalAccessResponse有一个属性:AccessRights

这里返回当前用户对这个实体具有的所有权限,比如:
AppendAccess,AssignAccess,CreateAccess,DeleteAccess,ReadAccess等等。