Articles → MICROSOFT BOT FRAMEWORK → Set the order of questions in formflow in Microsoft Bot framework

Set the order of questions in formflow in

Microsoft Bot framework





public int Age;
public string Name;




Picture showing the bot asking to enter the name and age from the user in the default order

Click to Enlarge



public static IForm < FormFlowDemo > GetForm() {
  return new FormBuilder<FormFlowDemo>()
            .Message("Welcome to support chat system. Please enter the following information to serve you better")
            .Field(nameof(Name))
            .Field(nameof(Age)).Build();
}




Picture showing the bot asking to enter the name and age from the user in the specified order

Click to Enlarge


Complete code


using Microsoft.Bot.Builder.FormFlow;
using System;

namespace Bot_Application1.Dialogs { 
  [Serializable]
  public class FormFlowDemo {

    public int Age;
    public string Name;

    public static IForm < FormFlowDemo > GetForm() {
      return new FormBuilder < FormFlowDemo > ().Message("Welcome to support chat system. Please enter the following information to serve you better").Field(nameof(Name)).Field(nameof(Age)).Build();
    }
  }
}



Validate data inside the Field function






public static IForm <FormFlowDemo> GetForm() {
  return new FormBuilder < FormFlowDemo>()
      .Message("Welcome to support chat system. Please enter the following information to open bank account").Field(nameof(Name))
      .Field(nameof(Age), validate: async(state, response) =>{
    var validation = new ValidateResult {
      IsValid = true,
      Value = response
    };

    if (Convert.ToInt32(response) < 18) {
      validation.IsValid = false;
      validation.Feedback = "You are eligible to open bank account as you are below 18 years of age";
    }

    return validation;
  }).Build();
}





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, October 23, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250