Issue with CacheMetaData - Custom Activity Creation


@loginerror @DeanMauro @radu_bucur

Input:
1.)Column Names <string> / Column Indexes <int>
2.)InOutDataTable

I need to raise Validation Error in 2 cases:
i.) Column Names and Column Indexes are empty : “Please provide value to either fields”

ii.)Column Names and Column Indexers both have values : “Please select either of the fields”

Below is my code. And it is still throwing Validation error (PFA screenshot where Column Indexers = {0} and Column Names = empty)


public class RemoveMultipleColumns:CodeActivity
{

    [Category("Input")]
    [DisplayName("Column Indexes")]
    [Description("Array of column indexes")]
    public InArgument<int[]> ColumnIndexes { get; set; }

    [Category("Input")]
    [DisplayName("Column Names")]
    [Description("Array of column names")]
    public InArgument<string[]> ColumnNames { get; set; }


    [Category("Input")]
    [RequiredArgument]
    [DisplayName("Input / Output DataTable")]
    [Description("Input/Output DataTable")]
    public InOutArgument<System.Data.DataTable> InOutDataTable { get; set; }

    protected override void CacheMetadata(CodeActivityMetadata metadata)
    {
        base.CacheMetadata(metadata);

        if ((ColumnIndexes != null) && (ColumnNames != null) )
        {
            ValidationError error = new ValidationError("You can NOT give both fields: Column Indexes and Column Names values");
            metadata.AddValidationError(error);
        }

        if ((ColumnIndexes == null) && (ColumnNames == null))
        {
            ValidationError error = new ValidationError("Please provide value to either field Column Indexes OR Column Names");
            metadata.AddValidationError(error);
        }
        
       
    }

    protected override void Execute(CodeActivityContext context)
    {
        //logic
    }


    
}

This will sound random but try putting base.CacheMetadata at the end of the method instead of the beginning.

5 Likes

Thank you so much for your help it’s working now :slight_smile:

@devashish1989 As a sidenote, check out our new Activity Creator extension for Visual Studio for an easier time building activities:

1 Like

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