Create Instance Var Records from Webform Fields
On the Model Properties page, select the Trigger tab, then select the Create Instance Var Records from Webform Fields checkbox. It will be enabled only when trigger type of “Webform” is selected. It is not available for any other type of model trigger type.
Current working design: A webform will have many user fields including text field, date fields, check boxes, drop downs, etc. There is a corresponding workflow model for the web form that processes the data submitted by the webform and takes necessary actions. To process these data values, the workflow engine needs to know the names (IDs) of the user fields present on the webform so that it can extract their values. This ‘connecting the workflow model with the webform fields’ can be done by adding a specific section for the workflow model in the DBCustom.xml file OR by adding a variable to the workflow model with matching name for each field that the workflow engine/model needs to know about. For this ‘Create Instance Var Records from Webform Fields’ setting, we will just focus on the workflow models set up with model variables. When a variable is created, it creates a record in the wf_instance_var table. That is how the engine reads the webform field values. If there are no variables defined in the workflow model, the field values will not be available in the wf_instance_var table, hence not available for the engine.
The problem: If you need to add more fields to the web form or want to change the ID of the fields on the webform, it requires the workflow model to be updated as well to match with the web form changes. This can be done easily when there are only a handful of changes. However, if you are making major changes to the webform especially adding a few dynamically created fields/line items on demand in the web form, this could require lots of new variables being added to the workflow model which can be a maintenance problem.
With this Feature:
On the Workflow engine side:
Workflow variables are no longer required to be added to the model when this check box is checked. When the workflow engine reads the webform instance the first time, it reads the ‘WebformData’ section of the instance which has all the webform field names and their values. If there is any value present for the field, then it checks if there is a wf_instance_var.wf_name record (for the given workflow model and wf_key). If the record does not exist (which will be true for most of them), it will create the record. It will not create the record for the empty field values to save the database table space. For the hard coded variables on the workflow model, the records would be there already. This feature dynamically creates fields based on what is submitted from the webform without having to add the variables to the workflow model.
Now the wf_instance_var table has all data values from the web form (plus the hard coded variables on the Workflow model, if any).
Let’s say you open the webform from the workflow task list and modify some values on the webform. It could be setting some value for a previously empty field or updating the value to something else or clearing some value. The workflow engine will have ‘WebformData’ data from the updated instance and it will check/compare the values and either add a new wf_name record to the wf_instance_var table or update the existing values to the new values.
On the Workflow model side:
A SQL query will read wf_instance_var data for the given model, wf_key and put them all in a container. A non-BT20 based simple data fetch has been added to IFAS.Common (image #1).
Read the data values from this container when needed. If the field name is missing in the container, it means it has blank value. If you need to read the
value from the actual variables that some previous activity has set, you can read those from the variables object as shown in image #2.
Image #3 shows how to call and use the function.
NOTE: It requires C# type activity.

Image#1 – Read wf_instance_var data

Image #2 – Read the data values from the container (or actual variables object)

Image #3 - Calling the functions
Workflow is updated for the web forms to not require any variables defined in the workflow model or any section in the DBCustom.xml file for the purpose of moving the webform data to the wf_instance_var table. The workflow engine will move the data from the initial workflow instance that will have all the values. It will also add/update the additional values if the web form is updated from the workflow task list.
wf_instance_var data values can be loaded to a key/value pair (known as dictionary) in the C# activity with a ‘Model’ call:
private Dictionary<string,string> _variableDataList = new Dictionary<string, string>();
_variableDataList = Model.GetVariableData(sModelId, sWFKey, nVersion);
Workflow model ID, key, version and other needed values can be collected with ‘Model’ call as:
WFInstance wfInstance = new WFInstanceClass();
wfInstance = Model.GetInstanceRecord();
XmlDocument xmlDoc = Model.GetInstanceData();
string sUrl = Model.GetWebrqbUrl(); //wwwServer value
string sConnection = Model.GetConnectionName();
string sCreator = "";
string sModelId = "";
string sWFKey = "";
int nVersion = 1;
if (wfInstance != null)
{
sModelId = wfInstance.ModelId;
sWFKey = wfInstance.Key;
nVersion = wfInstance.Version;
sCreator = wfInstance.Creator;
}

Figure 1 Creating a global variable
How to use/update the data form/to the dictionary.
string sValue = "";
if (_variableDataList.ContainsKey("SomeName"))
{
sValue = _variableDataList["SomeName"]; // Get the value of wf_value from wfName in wf_instance_var
sValue = "some new value"; //value is modified
_variableDataList["SomeName"] = sValue; // update the content in the global object
}

Figure #2 Loading the variables data to the global variable
If some changes were made to the variable data, it can be saved back to the wf_instance_var table. Server-side logic will check if any of the values were changed from the original content and will update the data, if needed.
//NOTE: Make sure to do this call at the end of the C# activity.
Model.UpdateVariableData(sModelId, sWFKey, nVersion, _variableDataList , sCreator);
C# module of the WF model is also updated to add a few more helpful function calls.
Model.WriteTrace("Some Test"); // Enable BT50WF.MANAGED module trace
Some data fetch functions (from DataHelper) and data conversion functions from BTHelper examples.
Example 1 (Data fetch using a Sql query and string to integer data conversion):
string sql = "select us_no, us_email from us_usno_mstr where us_id='xyz'";
DataTable table = DataHelper.GetTableDataDirectFetch(sql);
if (table.Rows.Count > 0)
{
string sUsNo = table.Rows[0]["us_no"].ToString();
string sEmail = table.Rows[0]["us_email"].ToString();
int nUsNo = BTHelper.To<int>(sUsNo);
}
Example 2 (Data fetch using a Sql query, reading the named column values and string to date/time data conversion):
string sql = "select beg as OrigHireDt, bargunit as BargUnit, department as Dept, Name, type as EmpType, Worksite, hdt as HireDt, id as EEID from hr_empmstr where id='xyz'"
DataTable table = DataHelper.GetTableDataDirectFetch(sql);
if (table.Rows.Count > 0)
{
string sOrigHireDt = table.Rows[0]["OrigHireDt"].ToString();
DateTime dtOrigHireDt = BTHelper.To<DateTime>(sOrigHireDt);
}
Sending requests through the ‘Model’ call:
string sXmlRequest = "<sbixml><NetSightMessage>";
...
sXmlRequest += "</NetSightMessage></sbixml>";
XmlDocument oResponseXml = Model.SendRequest(sXmlRequest);
Downside of this Feature:
Since this checkbox will create wf_instance_var records for every webform field that has a value, the workflow model may not need all those values. Therefore, there will be a waste of database table space for unused values. This feature will be useful when there will be lots of workflow model variables to be created or the webform has dynamically created fields/line items that the user may create based on the needs, for example expense line items.