CRM 2011工作流程:查找先前的值 [英] CRM 2011 Workflows: Finding the previous values
问题描述
我目前有一个工作流,当更改某个十进制字段时会触发该工作流。
I currently have a workflow which is triggered when a certain decimal field is changed.
是否有可能通过工作流获得新旧值之间的差异?
Is it possible to get the difference between the old and new values via a workflow?
推荐答案
最后有时间进行测试,使用工作流完全可以检索工作流中的前置值。
Finally had the time to test this, and it is perfectly possible to retrieve the pre values in a workflow using a workflow assembly.
这就是我所做的:
我在Contact上创建了一个工作流,并在LastName上触发了一个工作流。 工作流程包含对字段姓氏的引用以及自定义工作流程程序集。我打开了一个联系人,并将其姓氏从 Foo更改为 Bar
I created a workflow on Contact, with a trigger on LastName. The workflow contains a reference to the field lastname, and a custom workflow assembly. I opened a contact and changed it's lastname from 'Foo' to 'Bar'
自定义工作流程程序集的代码:
Code of the custom workflow assembly:
protected override void Execute(CodeActivityContext context)
{
IWorkflowContext workflow = context.GetExtension<IWorkflowContext>();
Entity preImage = workflow.PreEntityImages.Values.FirstOrDefault();
string content = RetrievePreImageLastname(preImage);
using (StreamWriter writer = new StreamWriter(@"C:\temp\log.txt", true))
{
writer.WriteLine("writing workflow assembly");
writer.Write(content);
}
}
public string RetrievePreImageLastname(Entity value)
{
if (value == null)
return "PreImage is Empty";
return string.Format("lastname pre image value: {0}", value.GetAttributeValue<string>("lastname"));
}
这是输出:
编写工作流程程序集
姓氏前映像值:Foo
希望这对将来使用的任何人都有帮助。
Hope this helps anyone in for future use.
这篇关于CRM 2011工作流程:查找先前的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!