We have inbuilt foreachwithbodyfactory activity which we need to pass datatablename.Asenumarable but in our requirement
we do not want to pass this asenumarable with datatablename.
we are creating our own custom foreachwithbodyfactory activity.
we have created someting but fully it is not working.
below is our activity class and designer page.
activity.cs
[Designer(typeof(mydesignerpage)), ContentProperty("Child")]
public sealed class MyActivity : NativeActivity, IActivityTemplateFactory
{
public ActivityAction Child { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
metadata.AddDelegate(Child);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleAction(Child);
}
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
return new MyActivity
{
Child = new ActivityAction()
};
}
}
mydesignerpage
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" Height="500" Width="400">

Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 10:02 AM EDT
1. Modify the `MyActivity` class to inherit from `NativeActivity
public sealed class MyActivity : NativeActivity, IActivityTemplateFactory { public ActivityAction Body { get; set; } protected override void CacheMetadata(NativeActivityMetadata metadata) { metadata.AddChild(Body); } protected override void Execute(NativeActivityContext context) { context.ScheduleActivity(Body); } Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target) { return new MyActivity { Body = new ActivityAction() }; } }2. Update the `mydesignerpage` XAML file to bind the `Body` property instead of `Child` property:
By making these modifications, you should be able to create a custom `ForEachWithBodyFactory` activity and use it in your workflow without needing to pass an `IEnumerable` with a `DataTable` name.
Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 10:05 AM EDT
Using a custom ForEachWithBodyFactory activity, as described in the modified code snippets, has its merits and demerits:
Merits:
1. Creating a custom activity allows you to tailor it to your specific requirements and integrate it seamlessly into your workflow.
2. Once created, the custom activity can be reused across multiple workflows, saving development time and effort.
3. The custom activity encapsulates a specific functionality, making the workflow design more modular and easier to understand.
4. You have control over the behavior and implementation details of the activity, allowing you to customize it as needed.
Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 10:05 AM EDT
Demerits:
1. Creating a custom activity involves understanding the workflow framework and implementing the necessary interfaces, which can be more complex compared to using built-in activities.
2. Custom activities require ongoing maintenance and updates to ensure compatibility with future versions of the workflow framework.
3. Debugging custom activities may require additional effort, as issues could arise from custom implementation logic.
4. Creating custom activities requires knowledge of the workflow framework and associated technologies, which may have a learning curve if you're new to the concepts.
raj rajRank #5,629 · 292 reputationPosted May 21, 2023, 11:07 AM EDT
getting conversion error we can not convert
Severity Code Description Project File Line Suppression State' to 'System.Activities.Activity' Excel ForEachDataTableActivity.cs 31
Error CS1503 Argument 1: cannot convert from 'System.Activities.ActivityAction
Active
after adding body control above text box showing read only