How to expose the business input as variable?

Feb 2, 2014 at 6:18 AM
Hi sshown,
I am working a project, and I believe "FlowTasks" have the main function I need, one scenario is that I need put a decision activity based on user original input, for example, as the HR example process, as the original input, the user will first select "administration" or "developer" then upload his/her resume, based on this input I'd like have a different branch of the workflow, I know there is some way to handle this in flowtasks, but I 'd like hear your suggestion first.

Thanks,

Jacob
Coordinator
Feb 2, 2014 at 9:35 PM
Hi Jacob,
it really depends on how you design the view for your task.
You could use the result from the task; when the user complete the task i.e. click the "Accept" or "Reject" button, you can check what the user clicked and do different things. Please note that you can change the name of these buttons.
The sample workflow ~\Workflows\ServiceWorkflows\SampleWf4.xamlx show how to do this.

If you want to pass more complex data from the UI to the workflow then you can use the parameters. In FlowTasks there is the convention that if you prepend the ID of a HTML control with "TaskParameter" then this will be pass to the workflow as a parameter, so the workflow engine can then use it.
In the HR example I've defined: <input id="TaskParameterCandidateName" name="TaskParameterCandidateName" type="text" /> In this way I could then use "CandidateName" inside the workflow.
You could even create a custom activity, which you can then use in the workflow designer, that read the parameters and set a flag that specifies which branch to run. Example:
public class CheckMyParametersAndDecideWhichBranch : NativeActivity
{
    public OutArgument<string> DecideBranch { get; set; }
    
    /* this is the task code that specifies the task which has just set the parameters from the UI */
    public InArgument<string> TaskCode   { get; set; } 

    protected override void Execute(NativeActivityContext context)
    {
        var workflowStatus = context.GetExtension<WorkflowStateData>();

        /* Read the parameters */
        var param1 = workflowStatus.Tasks[TaskCode.Get(context)].Parameters["MyParameter1"];
        var param2 = workflowStatus.Tasks[TaskCode.Get(context)].Parameters["MyParameter2"];

        /* Based on the values of the parameters set the apropriate result for example: */
        DecideBranch.Set(context, "IF-BRANCH");
    }
}
Feb 3, 2014 at 12:55 AM
Thank you so much!
Feb 3, 2014 at 1:01 AM
Sorry, actually one more question, right now the parameters are basically a dictionary include base types (int, string, bool etc), is it possible to pass complex types (for example I want to define a JobApplication class and pass it into flowtasks)? I was thinking use serialize and de-serialize, what is your idea on that?
Feb 3, 2014 at 2:19 AM
Edited Feb 3, 2014 at 2:21 AM
I just tried to re-sort my idea or "requirements", so here is the scenario:

let 's say we have a HR application, which process the Job applications from internet, now we want to use flowtasks to drive the approve workflow/UI, and in the HR application we have a domain class - say JobApplication, and we want to author the workflow (use the workflow designer in visual studio instead of hard code them) to different branch.

so I think I need to:

wrap the instance of the JobApplication class to kind of DTO (data transfer object) object, and include the DTO object in the request which will be sent to flowtasks, and in the flowtasks I will have a custom activity to retrieve the DTO object and assign it a variable, now the author/developer of the workflow can author the workflow based the whatever public data of the DTO object.

now the hard part to me is that I need a way to pass the DTO object to flowtasks, of course I can wrap the properties/data of the DTO in parameters, but I think there must be a better way to handle this.

thanks in advance.
Coordinator
Feb 3, 2014 at 3:22 AM
Interesting... So If I understand you correctly you would like to have the way to start a workflow passing in an object (must be serializable).

At the moment you can only pass a list of “PropertyInfo” which at the moment is defined like this:
public class PropertyInfo
{
    public string Name { get; set; }
    public string Value { get; set; }
    public string Type { get; set; }
}
At the moment the Value type is a string, but you really would like it to be a generic object. Am I right?

A work around for now would be to serialize your DTO object using a XmlSerializer and then assign to Value the Xml which represent the object serialized. Then in your custom activity you can deserialize the Xml to your particular DTO object.
Feb 3, 2014 at 5:45 AM
Yes, you are right, and I think this make sense, since most of our application will use object (complex type) :)