locked
parameters in activities RRS feed

  • Question

  • Hello All,

    At the beginning I have to say that I am new in here and I am quite new in WF.
    I have a question regarding passing argument between activities which I put on flowchart.
    For example i have an activity doing some bussines code, and after this activity I put second activity in my during my application is open.
    How can I say in first activity that for example it is pass without any problems, and then check in second activity that state? I mean how to check in second one if fist one set let say true or false.

    Thanks

    Wednesday, June 16, 2010 10:45 AM

Answers

  • I'm not sure if I understand your question, but I wrote it wrong in my previous reply. Do you mean how to set the value for the OutArgument in your CodeActivity<bool> so that this boolean value can be passed to the second custom activity for checking status?

    If you want to use OutArgument, you can use the Set() method in your CodeActivity<bool>: 

      public sealed class MyCodeActivity : CodeActivity<bool>
      {
        [RequiredArgument]
        public OutArgument<bool> MyResult { get; set; }
    
        protected override bool Execute(CodeActivityContext context)
        {
          // set the OutArgument
          MyResult.Set(context, true); // or false
    
          // return whatever value you want
          return whateverVar;
        }
      }

     or, you can simply get the return value of your CodeActivity<bool> from Result:

    Variable<bool> storeWhateverVar = new Variable<bool>();
    
    new MyCodeActivity()
    {
      ...
      Result = storeWhateverVar ,
    }
    

    Here's a sample CodeActivity:

      public sealed class MyCodeActivity : CodeActivity<string>
      {
        [RequiredArgument]
        public OutArgument<string> MyOutArg { get; set; }
    
        protected override string Execute(CodeActivityContext context)
        {
          MyOutArg.Set(context, "MyOutArg value");
          return "My return value";
        }
      }
    

    and the parent workflow that retrieves the value:

          Variable<string> getOutArg = new Variable<string>("getOutArg", "Init value for MyOutArg");
          Variable<string> getReturnValue = new Variable<string>("getReturnValue", "Init value for return value");
    
          new Sequence()
          {
            Variables = { getOutArg, getReturnValue },
            Activities = 
            {
              new MyCodeActivity()
              {
                Result = getReturnValue, // retrieve the return value of the CodeActivity
                MyOutArg = getOutArg,   // retrieve the value from the OutArgument
              },
              new WriteLine()
              {
                Text = getOutArg
              },
              new WriteLine()
              {
                Text = getReturnValue
              }
    
            }
          };
    

    and the output:

       MyOutArg value
       My return value

     

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Andrew_Zhu Wednesday, June 23, 2010 1:13 AM
    Thursday, June 17, 2010 3:43 PM
  • to answer your question

    And now I have additional question. How can I set i code that my activity always will have set Checkstate(bool) as my VariableName?

    instead of this ModelItem.Properties["CheckState"].SetValue(myArg);

    can you have a try on following code?

    it seems you are using InArgument type for CheckState

    Item.Properties["CheckState"].SetValue(new InArgument<bool>(new VisualBasicValue<bool> { ExpressionText = "variable1"}));

    if you want to use outArgument type for CheckState

    you can use following

    Item.Properties["CheckState"].SetValue(new OutArgument<bool>(new VisualBasicReference<bool>{ExpressionText="variable1"}));

    else if you want to set your variable name to Expression Textbox which is not argument type

    you can use following


    Item.Properties["CheckState"].SetValue(new VisualBasicValue<bool> { ExpressionText = "variable1" });

    • Marked as answer by Andrew_Zhu Wednesday, June 23, 2010 1:13 AM
    Thursday, June 17, 2010 6:32 PM

All replies

  • I assume you mean you want to have a way for the custom activity to set a value and pass it back to the workflow for evaluation?

    You can create an OutArgument<bool> in your custom activity, e.g.:

       public OutArgument<bool> Result { get; set; }

     and then in the workflow that consumes this custom activity, bind this OutArgument to a variable, e.g.:

     

     

       new MyCustomActivity()

       {

          ......

     

     

          Result = new OutArgument<bool>(decisionVariable)

       },

    The value that you set in your custom activity will be stored in the variable which you can check its value.

    You can download the samples and look at the CodedWorkflow sample (WF\Basic\Built-InActivities\Procedurals\CodedWorkflow) which uses an OutArgument in the PromptInt class. This sample is not specifically used for demonstrating OutArgument but it can serve our purpose here.

    Please let me know if you think this is not clear enough. :)

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    Wednesday, June 16, 2010 3:26 PM
  • Hello,

    Thank you for reply, and thank you for your help.
    I made it like this:

    public

     

     

    InArgument<bool> CheckState { get; set; }

    and my parents activieties returns bool,
    myActivity: CodeActivity<bool>
    ...
    return Result.Get(context);

    It works when il will set Variable form my result out argument. (add bool variable to flowchart, and than put VariableName as CheckState inArgument<bool>)
    And now I have additional question. How can I set i code that my activity always will have set Checkstate(bool) as my VariableName?

    I was try to do it in my DesignerActivity

    VisualBasicValue

     

     

    <bool> variable =new VisualBasicValue<bool>();
    ...
    ModelItem.Properties["CheckState"].SetValue(variable);
    And Yes I am able to set value but only for true or false, but never as VariableName?
    Have you got any ideas?

    Thank you

    Thursday, June 17, 2010 6:34 AM
  • Ok I have it for inArgument:

     

     

    Argument myArg =
    Argument.Create(typeof(bool), ArgumentDirection.In); myArg.Expression = new VisualBasicValue<bool>
    {
    ExpressionText =
    "variable1"
    };
    ModelItem.Properties[
    "CheckState"].SetValue(myArg);

    Can I do something similar for outArgument which is result of my codeActivity<bool>?

    Thursday, June 17, 2010 7:00 AM
  • I'm not sure if I understand your question, but I wrote it wrong in my previous reply. Do you mean how to set the value for the OutArgument in your CodeActivity<bool> so that this boolean value can be passed to the second custom activity for checking status?

    If you want to use OutArgument, you can use the Set() method in your CodeActivity<bool>: 

      public sealed class MyCodeActivity : CodeActivity<bool>
      {
        [RequiredArgument]
        public OutArgument<bool> MyResult { get; set; }
    
        protected override bool Execute(CodeActivityContext context)
        {
          // set the OutArgument
          MyResult.Set(context, true); // or false
    
          // return whatever value you want
          return whateverVar;
        }
      }

     or, you can simply get the return value of your CodeActivity<bool> from Result:

    Variable<bool> storeWhateverVar = new Variable<bool>();
    
    new MyCodeActivity()
    {
      ...
      Result = storeWhateverVar ,
    }
    

    Here's a sample CodeActivity:

      public sealed class MyCodeActivity : CodeActivity<string>
      {
        [RequiredArgument]
        public OutArgument<string> MyOutArg { get; set; }
    
        protected override string Execute(CodeActivityContext context)
        {
          MyOutArg.Set(context, "MyOutArg value");
          return "My return value";
        }
      }
    

    and the parent workflow that retrieves the value:

          Variable<string> getOutArg = new Variable<string>("getOutArg", "Init value for MyOutArg");
          Variable<string> getReturnValue = new Variable<string>("getReturnValue", "Init value for return value");
    
          new Sequence()
          {
            Variables = { getOutArg, getReturnValue },
            Activities = 
            {
              new MyCodeActivity()
              {
                Result = getReturnValue, // retrieve the return value of the CodeActivity
                MyOutArg = getOutArg,   // retrieve the value from the OutArgument
              },
              new WriteLine()
              {
                Text = getOutArg
              },
              new WriteLine()
              {
                Text = getReturnValue
              }
    
            }
          };
    

    and the output:

       MyOutArg value
       My return value

     

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Andrew_Zhu Wednesday, June 23, 2010 1:13 AM
    Thursday, June 17, 2010 3:43 PM
  • to answer your question

    And now I have additional question. How can I set i code that my activity always will have set Checkstate(bool) as my VariableName?

    instead of this ModelItem.Properties["CheckState"].SetValue(myArg);

    can you have a try on following code?

    it seems you are using InArgument type for CheckState

    Item.Properties["CheckState"].SetValue(new InArgument<bool>(new VisualBasicValue<bool> { ExpressionText = "variable1"}));

    if you want to use outArgument type for CheckState

    you can use following

    Item.Properties["CheckState"].SetValue(new OutArgument<bool>(new VisualBasicReference<bool>{ExpressionText="variable1"}));

    else if you want to set your variable name to Expression Textbox which is not argument type

    you can use following


    Item.Properties["CheckState"].SetValue(new VisualBasicValue<bool> { ExpressionText = "variable1" });

    • Marked as answer by Andrew_Zhu Wednesday, June 23, 2010 1:13 AM
    Thursday, June 17, 2010 6:32 PM