I inherited a CRM project with several workflows that do very similar tasks, basically they receive an input string and output a OptionSet value for that string. Since we need a new Workflow for each OptionSet there is a lot of duplicated code I am hoping to improve. They way I went about it was to create an abstract class
public abstract class MyBaseWorkflow : CodeActivity
{
protected sealed override void Execute(CodeActivityContext executionContext)
{
// this is pseudo-code and I know it works, the last line is the issue
var input = ReadInputValue();
var query = BuildQuery();
var option = MatchWithInput(queryResults, input);
WriteToOutput(..., option);
}
protected string BuildQuery();
protected string ReadInputValue();
protected string WriteToOutput(CodeActivityContext executionContext, OptionMetadata selectedValue);
}
then on my workflows I have (I omitted the BuildQuery and ReadInputValues since I know those work just fine)
public class MyWorkflow : MyBaseWorkflow
{
[Input("Account MyFieldAsText Input")]
public InArgument<string> OptionSetStringInput { get; set; }
[Output("Account MyFieldOptionSetValue Output")]
[AttributeTarget("account", "myField")]
public OutArgument<OptionSetValue> OptionSetValueOutput { get; set; }
protected overide string WriteToOutput(CodeActivityContext executionContext, OptionMetadata selectedValue)
{
this.OptionSetValueOutput.Set(executionContext, new OptionSetValue(selectedValue.Value.Value));
}
}
I did some tracing and was able to see the proper value being written to the property however nothing seemed to be outputted to the next step.
I have been thinking of doing something like this: context.OutputParameters["myField"] = selectedValue to see if that sets the value but I'm not sure how to go about it.
Any idea what might be going wrong?
Do output parameters have any constraints in inheritance?
Should I avoid inheritance as a rule of thumb while working with workflows and plugins?