locked
How to create a variable during custom activity code? is that possible? RRS feed

  • Question

  • Hi,

    How do I create a new out arguement variable from custom activity during execution? Is that possible? I don't want to do it from outside of my custom workflow. I saw some sample in this forum and blog which use modelItem, i believe that are need to implement outside of my custom activity. I would like to do it from inside my custom activity code.

    Regards,

    Bandu

    Tuesday, December 6, 2011 11:19 AM

Answers

  • OK, you're asking about activity design time, not activity run time.

    You can do this from custom activity code, but there are some challenges in figuring out when is the right time to add/delete the variable, because the events received by subclassing ActivityDesigner don't explicitly have this information. You might need to override ActivityDesigner.OnModelItemChanged() and register for change notifications from the global ModelService, which comes from EditingContext.Services.GetService<ModelService>.

    You should also probably be using the .Design.dll IRegisterMetadata technique in order for your custom designer to be loaded into VS, if that is your scenario.

    Tim

    • Marked as answer by Bandu Friday, December 9, 2011 1:13 PM
    Wednesday, December 7, 2011 6:01 PM

All replies

  • You can't create Variables in an activity at runtime (during Execute()), they need to be fixed/constant from the time of CacheMetadata() onwards, which is before Execute() is called.

    Would you be OK for your scenario with using a List or Dictionary variable which you can populate with values at runtime, instead?
    Tim
    Tuesday, December 6, 2011 11:15 PM
  • thanks, In my scenario, I would like to add variable during design time. By the time my main custom activity get drag and drop into desinger surface, I would like to add a variable to the designer automatically from the code. And if possible, I also want to remove it back when it get deleted from the desinger surface. But I would like to do it from custom activity code, instead of rehost designer environment. Regards, Bandu
    Wednesday, December 7, 2011 10:21 AM
  • OK, you're asking about activity design time, not activity run time.

    You can do this from custom activity code, but there are some challenges in figuring out when is the right time to add/delete the variable, because the events received by subclassing ActivityDesigner don't explicitly have this information. You might need to override ActivityDesigner.OnModelItemChanged() and register for change notifications from the global ModelService, which comes from EditingContext.Services.GetService<ModelService>.

    You should also probably be using the .Design.dll IRegisterMetadata technique in order for your custom designer to be loaded into VS, if that is your scenario.

    Tim

    • Marked as answer by Bandu Friday, December 9, 2011 1:13 PM
    Wednesday, December 7, 2011 6:01 PM
  • Thanks, Tim.

    Its explain my confusion.

    • Marked as answer by Bandu Friday, December 9, 2011 1:13 PM
    • Unmarked as answer by Bandu Friday, December 9, 2011 1:13 PM
    Thursday, December 8, 2011 10:22 AM