Dynamic Input Dialogue in Blue Prism- Attended Automation-3 (VBO Download Link Below)

In our previous topics, we learnt about how to emulate the message box property using Blue prism which would enable to send popup messages to the user on run time resources . It pauses the execution until someone manually clicks on the OK Button.

You can read the post here.

Message Box and Request Credentials Using Blue Prism (Attended Automation)

We also saw how to take user inputs by extending the same VBO. You can read about it here.

Input Dialogue(Run time User Input) in Blue Prism- Attended Automation-2

In this post,we will extend the same code logic to enable taking multiple fields in a collection as input and then generate a form using the column names dynamically through the code, gather inputs with validation and finally store the information in the same collection to provide output.

You can also refer to the post link given above to get acquainted to the basics of code stages.

You have to follow the same principles as described in the above article and add a new global code with the below snippet.

Code for Taking one input in the dialogue box:

private static DataTable DynamicDialog(string formname,DataTable dataTable)
{
System.Drawing.Size size = new System.Drawing.Size(300, dataTable.Columns.Count*80);
Form inputBox = new Form();
inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
inputBox.ClientSize = size;
int ylocation = 5;
inputBox.Text = formname;
for (int intColumn = 0; intColumn < dataTable.Columns.Count ; intColumn++)
{
System.Windows.Forms.Label label = new Label();
label.Size = new System.Drawing.Size(size.Width – 140, 23);
label.Location = new System.Drawing.Point(5, ylocation);
label.Text = dataTable.Columns[intColumn].ColumnName.ToString();
ylocation = ylocation + 30;
inputBox.Controls.Add(label);
string input = “Enter ” + dataTable.Columns[intColumn].ColumnName.ToString() + ” here…”;
System.Windows.Forms.TextBox textBox = new TextBox();
textBox.Size = new System.Drawing.Size(size.Width – 10, 23);
textBox.Location = new System.Drawing.Point(5, ylocation);
textBox.Name = dataTable.Columns[intColumn].ColumnName.ToString();
ylocation = ylocation + 30;
textBox.Text = input;
inputBox.Controls.Add(textBox);
}
Button okButton = new Button();
okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
okButton.Name = “okButton”;
okButton.Size = new System.Drawing.Size(75, 23);
okButton.Text = “&OK”;
okButton.Location = new System.Drawing.Point(size.Width – 80 , ylocation);
ylocation = ylocation+30;
inputBox.Controls.Add(okButton);
Button cancelButton = new Button();
cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
cancelButton.Name = “cancelButton”;
cancelButton.Size = new System.Drawing.Size(75, 23);
cancelButton.Text = “&Cancel”;
cancelButton.Location = new System.Drawing.Point(size.Width – 80, ylocation);
inputBox.Controls.Add(cancelButton);
inputBox.AcceptButton = okButton;
inputBox.CancelButton = cancelButton;
DialogResult result = inputBox.ShowDialog();
DataRow dr;
dr = dataTable.NewRow();
for(int i=0;i< inputBox.Controls.Count-1;i++)
{
if (inputBox.Controls[i].GetType().FullName == “System.Windows.Forms.TextBox”)
{
dr[inputBox.Controls[i].Name] = inputBox.Controls[i].Text;
}
}
dataTable.Rows.Add(dr);
return dataTable;
}

Initialize Page Global Code will look like:

Now you can call this function “DynamicDialog”  with one string type input argument to display the Form name and another Collection type argument which will contain the field names as column names. It will return a collection which will contain all the values captured from the form.

 

 

Code to be used: 

Updated_Fields=DynamicDialog(Form_Name,Fields);

Where Form_name is the form name, Fields is the input collection and Updated_Fields is the output collection with value.

Important Note: If you don’t key in the values as per the field type defined in the input collection, you will get an error.

 

The Input Dialogue Box will look as below:

Value Returned will be stored in the Updated_Fields collection.

Download the VBO from here.

Download Link:


Happy learning.!!!

 

 

Please follow and like us: