• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

norman

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

在Workflow E-mail中添加注释

        在CRM如何轻易克服的一些限制,在发送电子邮件的活动中,加载注释到电子邮件后面。
        我在我的工作流中做了一个新的activity,使用到以下代码。
Code
using System;
using System.Workflow.ComponentModel;
using System.Workflow.Activities;
using System.Web.Services.Protocols;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.Workflow;
using System.Collections;
using System.Text;

namespace SonomaPartners.Crm.Workflow.Utilities
{
    [CrmWorkflowActivity(
"Format Notes", "Utilities")]
    
public partial class FormatNotes : SequenceActivity
    {
        
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            IContextService contextService 
= (IContextService)executionContext.GetService(typeof(IContextService));
            IWorkflowContext ctx 
= contextService.Context;
            ICrmService service 
= ctx.CreateCrmService();

            
this.FormattedNotes = BuildNotesString(service, ctx.PrimaryEntityId);

            
return base.Execute(executionContext);
        }

        
public static DependencyProperty FormattedNotesProperty = DependencyProperty.Register("FormattedNotes", typeof(string), typeof(FormatNotes));
        [CrmOutput(
"Formatted Notes")]
        
public string FormattedNotes
        {
            
get { return (string)base.GetValue(FormattedNotesProperty); }
            
set { base.SetValue(FormattedNotesProperty, value); }
        }


        
private string BuildNotesString(ICrmService service, Guid id)
        {
            StringBuilder results 
= new StringBuilder();
            results.Append(
"Notes:<br>");

            BusinessEntityCollection notes 
= new BusinessEntityCollection();
            notes 
= RetrieveNotesForId(service, id);

            
foreach (annotation note in notes.BusinessEntities)
            {
                results.Append(
string.Format("{0}<br>", note.subject));
                results.Append(
string.Format("{0}<br><br>", note.notetext));
            }

            
return results.ToString();
        }

        
private BusinessEntityCollection RetrieveNotesForId(ICrmService service, Guid id)
        {
            QueryByAttribute query 
= new QueryByAttribute();
            query.EntityName 
= "annotation";
            query.ColumnSet 
= new ColumnSet(new String[] { "subject", "notetext", "createdby", "createdon" });

            query.Attributes 
= new String[] { "objectid" };
            query.Values 
= new Object[] { id };
            query.Orders 
= new ArrayList();
            query.Orders.Add(
new OrderExpression("createdon", OrderType.Descending));

            
try
            {
                RetrieveMultipleRequest request 
= new RetrieveMultipleRequest();
                request.Query 
= query;

                RetrieveMultipleResponse returnedNotes 
= (RetrieveMultipleResponse)service.Execute(request);
                
return returnedNotes.BusinessEntityCollection;
            }
            
catch (SoapException ex)
            {
                
throw new Exception(ex.Detail.InnerText);
            }
        }
    }
}

posted on 2009-02-12 14:04  strgvi  阅读(280)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3