How to get drop down value in Custom Activity

Hi Folks,

I have created a custom activity with drop down properties using Enum values as suggested. And could see the activity with drop down property with values. But how do i get the selected drop down value into my code.

public enum Days
{
Day1,
Day2
}
[Category(“ListCredential”)]
[RequiredArgument]
public Days Day{ get; set; }

Here’s what I did for my file type dropdown for one of my custom activities.

public enum fileType
    {
        CSV,
        TAB,
        XML,
        Excel
    }

[Category("Input")]
[RequiredArgument]
[Description("Output file type for report results.")]
public fileType ReportFileType { get; set; }

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
    {
        
        
        fileType ft = Token.Get(context);

The ft variable holds my file type.

Daniel,

Thanks for the reply. But I am facing not suitable method error.

I’m implementing the AsyncCodeActivity class because I make a HTTP request in my custom activity. To fully implement the AsyncCodeActivity class I have to override the BeginExecute and EndExecute functions.

If you’re just doing a regular activity without an asynchronous call then you are implementing CodeActivity, which has no override functions called BeginExecute and EndExecute. You’re getting the error because you’re trying to override a function that doesn’t exist.

Daniel,

I could not get the context of a enum values inside the method. And I assume the Token you mentioned is for http access.

Sorry, that code I was using above was pulled from an older sample that wasn’t working, that’s my mistake.

SPEnvironment isn’t an InArgument or OutArgument so you don’t actually need the context to get or set it. Instead, you should be able to do “SPEnvironment.ToString()” and that will return either “Online” or “OnPrem”.

Here’s some of the most recent activity code:

    public enum fileType
    {
        CSV,
        TAB,
        XML,
        Excel
    }

    ...

    [Category("Input")]
    [RequiredArgument]
    [Description("Output file type for report results.")]
    public fileType ReportFileType { get; set; }

    ...

    protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
    {
      ...
      //Add it to a dictionary
      dict.Add("ReportFileType", ReportFileType.ToString());
      ...
    }
1 Like

Thanks Daniel,

Finally it worked out.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.