【发布时间】:2019-06-29 20:54:32
【问题描述】:
我正在开发一个 Dynamics CRM CWA,它会根据名为“准备者”的文本字段更新“修改者”字段。我目前有 3 个错误,我需要一些帮助调试(见下文)。它们可能很容易修复,但我对编码相当陌生。任何帮助调试将不胜感激。谢谢!
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Runtime.Serialization;
namespace KED365.Workflows
{
/// </summary>
public class ModifiedBy : WorkFlowActivityBase
{
private Guid contactid;
[Input("User Full Name")]
public InArgument<string> UserFullName { get; set; }
/// <summary>
/// Executes the WorkFlow.
/// </summary>
/// <param name="crmWorkflowContext">The <see cref="LocalWorkflowContext"/> which contains the
/// <param name="executionContext" > <see cref="CodeActivityContext"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
/// The WorkFlow's Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the WorkFlow. Also, multiple system threads
/// could execute the WorkFlow at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in WorkFlows.
/// </remarks>
protected override void Execute(CodeActivityContext activityContext, IWorkflowContext workflowContext, IOrganizationService orgService, ITracingService tracingService)
{
//get entity record for which plugin was fired
Entity _target = (Entity)workflowContext.InputParameters["Target"];
//check if portaluser name is to be obtained from custom createby or from custom modifiedby
if (workflowContext.MessageName.ToUpper() == "CREATE")
{
contactid = _target.Attributes.Contains("new_createdby") ? _target.GetAttributeValue<EntityReference>("new_createdby").Id : Guid.Empty;
}
else
{
contactid = _target.Attributes.Contains("new_modifiedby") ? _target.GetAttributeValue<EntityReference>("new_modifiedby").Id : Guid.Empty;
}
//retrieve contact fullname from contactid
var _contact = activityContext.CreateQuery("contact").Where(c => c.GetAttributeValue<Guid>("contactid").Equals(contactid)).FirstOrDefault();
if (_contact != null)
{
if (_contact.Attributes.Contains("fullname"))
{
fullname = _contact.GetAttributeValue<string>("fullname");
}
//retrieve Systemuser that has same name as that of new_portalcreatedby/ //new_portalmodifiedby
Entity _user = context.CreateQuery("systemuser").Where(e => e.GetAttributeValue<string>("fullname").Equals(fullname)).FirstOrDefault();
if (_user != null)
{
//check if we need to update createdby or modifiedby
if (workflowContext.MessageName.ToUpper() == "CREATE")
{
_target["createdby"] = _user.ToEntityReference();
}
else
{
_target["modifiedby"] = _user.ToEntityReference();
}
//assign new target to plugin executioncontext
workflowContext.InputParameters["Target"] = _target;
}
}
}
}
}
错误 1:
严重性代码描述项目文件行抑制状态 错误 CS1061“CodeActivityContext”不包含“CreateQuery”的定义,并且找不到接受“CodeActivityContext”类型的第一个参数的扩展方法“CreateQuery”(您是否缺少 using 指令或程序集引用?)工作流 C:\用户\tgiard\Downloads\GetUserByName-master\GetUserByName-master\Workflows\ModifiedBy.cs 68 活动
错误 2:
严重性代码描述项目文件行抑制状态 错误 CS0103 当前上下文中不存在名称“全名”工作流 C:\Users\tgiard\Downloads\GetUserByName-master\GetUserByName-master\Workflows\ModifiedBy.cs 75 活动
错误 3:
严重性代码描述项目文件行抑制状态 错误 CS0103 当前上下文中不存在名称“上下文”工作流 C:\Users\tgiard\Downloads\GetUserByName-master\GetUserByName-master\Workflows\ModifiedBy.cs 79 活动
【问题讨论】:
-
很好奇你为什么使用 CWA 而不是普通的插件。您已经定义了一个 InputParameter,但您没有在代码中的任何地方使用它。自定义工作流活动的指导是您应该定义输入和输出参数,以便在设计器中使用自定义活动的人可以看到它在做什么。您可能希望使用自定义活动的输出来更新该值,而不是直接使用 Target 参数。 docs.microsoft.com/en-us/powerapps/developer/…
-
@JimDaly-MSFT-,CWA和普通插件有什么区别?我的印象是它们是同一回事。另外,关于我应该在哪里使用 InputParameter 有什么建议吗?这对我来说都是全新的,如果我遗漏了一些明显的东西,我深表歉意。谢谢!
-
推荐您从这里开始:docs.microsoft.com/en-us/powerapps/developer/… 请记住,CRM 使用现在称为 Common Data Service 的平台。自定义工作流组件,也称为工作流扩展,旨在提供 UI 以扩展工作流设计器。插件是为事件注册的,没有 UI。
-
我同意 Jim,这段代码应该在插件中
标签: dynamics-crm workflow