locked
Can an activity access the public arguments of its previous activity in workflow designer RRS feed

  • Question

  • I have two activities say ActicityA and ActivityB. ActivityA has one out argument of type string and it is bind to expression textbox to get value in for it. ActivityB has one in argument of type string and is bind to expression textbox to get value in for it. Now the scenario is at execution time I drop ActivityA in the designer surface, and enter value in the expressiontextbox "Hello World", as this expression is bind to out argument of this activity, so value is set into that out argument. Now I drop ActivityB in designer surface, having one expressiontextbox already bind to inargument.

    How is it possible that value of ActivityA expressiontextbox (bind to out argument) could be set to ActivityB expressiontextbox (bind to in argument), as ActivityB is dropped into designer surface?

    Monday, July 5, 2010 7:27 AM

Answers

  • can you try to use following code to set property value?

    mi.Properties["inputimodel"].SetValue(new InArgument<string>(new VisualBasicValue<string> { ExpressionText = "hello"}));

     

    let me know if this still doesn't work for you, I will write complete sample code for you tomorrow. Please also paste the activityB definition and your detail exception stack.

    Tuesday, July 6, 2010 8:35 AM

All replies

  • Create a variable say 'result' in the immediate common parent of the ActivityA and ActivityB. The variable result is in scope of both ActivityA and ActivityB. Set ActivityA out argument to result and set ActivityB in argument to result.

    ActivityB directly accessing ActivityA's public arguments is not possible.

    • Proposed as answer by Cecil du Toit Monday, July 5, 2010 10:15 AM
    Monday, July 5, 2010 9:18 AM
  • Thanks Suchi for reply. During design time of workflow, user drops ActivityA having one expression textbox and writes in this expressiontextbox "hello world", after this he drops another activity ActivityB having expressiontextbox in the designer. I want as user drops ActivityB in the designer, its expressiontextbox should display the value already set in expressiontextbox of ActivityA. For this scenario will we require Arguments or third variable that you mentioned? I require this at designing of workflow by using my own created rehosted workflow designer, not at execution time of workflow.
    Monday, July 5, 2010 12:25 PM
  • to answer your question how to set activityB argument automatically

    you can add modelchange event to your workflowdesigner

    when the event is invoked, you can check whether it's activityB added to designer surface, if it is, you can get the activityA value and set it to ActivityB value.

     about how to set argument value to the activity, you may refer to my post on this thread

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/b10a2954-9f0e-4675-ab12-b28cb4c201d3

    Tuesday, July 6, 2010 2:18 AM
  • I made following changes in my code;

    WorkflowDesigner workflowDesigner = new WorkflowDesigner();

    ModelService service = workflowDesigner.Context.Services.GetService(typeof(ModelService)) as ModelService;
    service.ModelChanged += new EventHandler<ModelChangedEventArgs>(wd_ModelChanged);

    private void wd_ModelChanged(object sender, ModelChangedEventArgs  e)
        {
        ModelChangedEventArgs changedEventArgs = e as ModelChangedEventArgs;
       
        IEnumerable<ModelItem> enumerator = e.ItemsAdded;

        foreach (ModelItem mi in enumerator)
            {
           IEnumerator<ModelProperty> temp =  mi.Properties.GetEnumerator();
            while(temp.MoveNext())
                {
                System.Windows.MessageBox.Show(temp.Current.Name);
                temp.Current.SetValue((object) "hello");
                break;
                }
            }
        }

     

    Now in this event handler i get last dropped activity in designer, but when i try to set any property of this added activity i get exception "ArgumentOutOfRangeException.  Index was out of range.Must be non-negative and less than the size of the collection.   "

     

    I tried to set property value even by this way, but got the same exception;

    mi.Properties["inputimodel"].SetValue((Object)"hello");

    Tuesday, July 6, 2010 7:48 AM
  • can you try to use following code to set property value?

    mi.Properties["inputimodel"].SetValue(new InArgument<string>(new VisualBasicValue<string> { ExpressionText = "hello"}));

     

    let me know if this still doesn't work for you, I will write complete sample code for you tomorrow. Please also paste the activityB definition and your detail exception stack.

    Tuesday, July 6, 2010 8:35 AM
  • Thanks a lot Ye Yu. It has resolved my problem.
    Tuesday, July 6, 2010 1:31 PM