Hello Mani,
Currently there is no way to dynamically create TPC widgets using the JavaScript API, you will need to create and configure them using the Page or Form designer in the Sitefinity backend.
Although, it is possible to filter a sub-grid or other form widgets based on values of fields within the form. You can do this using the Filters functionality. To add a filter based on the value of another widget, click Edit on the widget you are trying to filter in the TPC Form. Navigate to the Filters tab. Add a name to the filter, for example you can call it “FieldValue1” this will create a variable called @FieldValue1@. Under Filter Type select either Field Value or Optional Field Value depending on whether this filter should be required. For the value, select the field on which the value will be filtered and then click the + button to add the new filter. Now we have a variable called @FieldValue1@ which we can reference inside the FetchXML of the widget, it will automatically be replaced by the current value of the field. Within the TPC Fetch Builder of the widget, you can now add a FetchXML filter and reference the variable. Your fetch will look something like this:
<fetch version="1.0" mapping="logical" output-format="xml-platform">
<entity name="account">
<attribute name="accountid" />
<attribute name="name" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="name" operator="eq" value="@FieldValue1@" />
</filter>
</entity>
</fetch>
Please let me know if you have any other questions!
Cheers,
Josh