Reputation: 497
I would like to use the FormFlow dialog, but all the examples I've seen prompt the user to make a choice from an Enum. What if the values are from a database?
Upvotes: 2
Views: 1529
Reputation: 711
If you want to set dynamically values for a Field in a FormFlow you have to use Dynamically defined Fields.
Here is the doc and a full example of usage: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow-formbuilder?view=azure-bot-service-3.0
Basically, you have to get your data (from SQL DB or anywhere else) in the SetDefine function using the field.AddDescription and field.AddTerms functions.
:)
Upvotes: 2
Reputation: 123
Here is a demo of how to implement dynamic fields from database in formflow. Just replace StateClass to name of your class and ProperyName to name of your property. Unfortunally at this moment you wont find any information about FieldReflector in official documentation of Microsoft Bot Framework yet.
public static IForm<StateClass> BuildForm()
{
return new FormBuilder<StateClass>()
.Message("Start Message")
.Field(new FieldReflector<StateClass>(nameof(ProperyName))
.SetType(null)
.SetDefine(async (state, field) =>
{
List<string> list = QueryFromDatabase();
foreach (string item in list)
field
.AddDescription(item , item )
.AddTerms(item , item );
return true;
}))
.AddRemainingFields()
.OnCompletionAsync(async (context, state) =>
{
await context.PostAsync("Finish message");
})
.Build();
}
Upvotes: 2