Dynamics CRM - 访问新创建实体的工作流程中的属性

发布于 2024-08-21 00:24:46 字数 372 浏览 7 评论 0原文

我正在创建一个 Dynamics CRM 工作流程序集,当在任何类型的另一条记录上创建新注释时要执行该程序集。我需要能够访问新创建的 Note 实体上的属性 Prop1 以完成其他任务。

以前,我只访问过从字段或用户输入的值,但从未访问过新创建实体的属性。任何指导将不胜感激。

更新: 这是关于CRM 4.0的。

等待期间的更多信息: 最终,此工作流程序集将创建一封电子邮件,其中包含指向新创建的注释记录的父实体的链接。我需要获取的属性是 AnnotationId。创建注释记录后,我将根据新创建的注释的 AnnotationId 检索 ObjectId 和 ObjectTypeCode。 (如果你好奇的话)

I'm creating a Dynamics CRM workflow assembly to be executed when a new Note is created on another record of any type. I need to be able to access a property Prop1 on that newly created Note entity to accomplish other tasks.

Previously I've only accessed values that were input from a field or from the user, but never on a property of a newly created entity. Any guidance would be appreciated.

UPDATE:
This is regarding CRM 4.0.

More information while I wait:
Ultimately, this workflow assembly will create an email that contains a link to the parent entity of the newly created Note record. The property I need to get is the AnnotationId. Once the Note record is created, I will be retrieving the ObjectId and ObjectTypeCode based on the AnnotationId of the newly created Note.
(In case you were curious)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-08-28 00:24:46

好的,如果您使用 4.0 自定义工作流而不是 3.0 标注,则应该添加工作流程序集,并使用上下文服务和工作流的执行上下文从新注释中提取值。

请参阅下面的示例,了解如何使用上下文服务和当前执行上下文的 ID(这应该是您的注释)访问记录。

    /// <summary>
    /// The Execute method is called by the workflow runtime to execute an activity.
    /// </summary>
    /// <param name="executionContext"> The context for the activity</param>
    /// <returns></returns>
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {

        // Get the context service.
        IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
        IWorkflowContext context = contextService.Context;

        // Use the context service to create an instance of CrmService.
        ICrmService crmService = context.CreateCrmService(true);
        BusinessEntity newNote = GetNote(crmService, context.PrimaryEntityId);

        string noteAttrib;

         noteAttrib = newNote.Properties.Contains("AnnotationId") ? ((Lookup)newNote.Properties["annotationid"]).name.ToString() : null;

        return ActivityExecutionStatus.Closed;
    }

GetNotes 方法将是通过 CRM 服务调用按 Id 查询注释的标准查询,
下面是一个从 MSDN 稍微修改后返回注释的示例:

private BusinessEntity getNote(ICrmService service, guid noteid)
{
  // Create the column set object that indicates the fields to be retrieved.
  ColumnSet cols = new ColumnSet();

  // Set the columns to retrieve, you can use allColumns but its good practice to specify:
  cols.Attributes = new string [] {"name"};

  // Create the target object for the request.
  TargetRetrieveAnnotation target = new TargetRetrieveAnnotation();

  // Set the properties of the target object.
  // EntityId is the GUID of the record being retrieved.
  target.EntityId = noteid;

  // Create the request object.
  RetrieveRequest retrieve = new RetrieveRequest();

  // Set the properties of the request object.
  retrieve.Target = target;
  retrieve.ColumnSet = cols;

  // Execute the request.
  RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);
  return RetrieveResponse;
}

Ok so if your using 4.0 custom workflows and not 3.0 callouts, you should add a workflow assembly, and use the Context service and executing context of your workflow to pull the values from the new note.

See the example below on how to access a record using the context service and the ID of your current context of execution (that should be your note)

    /// <summary>
    /// The Execute method is called by the workflow runtime to execute an activity.
    /// </summary>
    /// <param name="executionContext"> The context for the activity</param>
    /// <returns></returns>
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {

        // Get the context service.
        IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
        IWorkflowContext context = contextService.Context;

        // Use the context service to create an instance of CrmService.
        ICrmService crmService = context.CreateCrmService(true);
        BusinessEntity newNote = GetNote(crmService, context.PrimaryEntityId);

        string noteAttrib;

         noteAttrib = newNote.Properties.Contains("AnnotationId") ? ((Lookup)newNote.Properties["annotationid"]).name.ToString() : null;

        return ActivityExecutionStatus.Closed;
    }

GetNotes method would be a standard query for notes by Id through a CRM service call,
here is an example slightly modified from MSDN to return a note:

private BusinessEntity getNote(ICrmService service, guid noteid)
{
  // Create the column set object that indicates the fields to be retrieved.
  ColumnSet cols = new ColumnSet();

  // Set the columns to retrieve, you can use allColumns but its good practice to specify:
  cols.Attributes = new string [] {"name"};

  // Create the target object for the request.
  TargetRetrieveAnnotation target = new TargetRetrieveAnnotation();

  // Set the properties of the target object.
  // EntityId is the GUID of the record being retrieved.
  target.EntityId = noteid;

  // Create the request object.
  RetrieveRequest retrieve = new RetrieveRequest();

  // Set the properties of the request object.
  retrieve.Target = target;
  retrieve.ColumnSet = cols;

  // Execute the request.
  RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);
  return RetrieveResponse;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文