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.
Here's what I did:
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"));
}
And this was the output:
writing workflow assembly
lastname pre image value: Foo
Hope this helps anyone in for future use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With