# Dataset as Template parameter

**URL:** <https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [November 3, 2022, 11:28am UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055 "2022-11-03T11:28:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [November 3, 2022, 11:28am UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/1 "2022-11-03T11:28:50Z")

</div>

Hi,

I have a template in vision in which I have params like Machine Name and 7 other params like day1 data,day2 data and so on.  
I would like to create a dataset param in template which holds the 7 params .

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/259516fb4569b5742e16b43fb956157050bcf2cf.png)  
At what trigger point should i have to add these 7 values to dataset.  
Kindly help me in going forward.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 3, 2022, 12:04pm UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/2 "2022-11-03T12:04:07Z")

</div>

I'm not quite sure what you want. Please elaborate.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [November 3, 2022, 12:08pm UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/3 "2022-11-03T12:08:42Z")

</div>

I have a template with fields: Label (Machine Name), Num Text field 1 (Data1) . . . Num Text field 7 (Data7)  
I have template parameters for above fields as :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/05faff9a75dfdd76a7265891fce155a0bad5c1b0.png)

Hence i want to populate those 7fields value to PlanDataset.

I have main screen in which this template will be populated based on the selected process,

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/847a97a6fd04e2ef39f86fd05ce65fa12a2041b1.png)  
When i enter the details in above fields i want to save the data.  
Currently i am trying in json. But i stuck at (Hence i want to populate those 7fields value to PlanDataset.)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 3, 2022, 12:15pm UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/4 "2022-11-03T12:15:54Z")

</div>

I see.

You need a script attached to your Save button that will use `system.dataset.toDataSet()` to assemble your dates as header strings and the three rows of data. Or perhaps make a 4-column dataset (with `t_stamp` as the first column), a static list of four column names, and seven rows of data.

The script would then assign the freshly-created dataset to the template parameter.

There are numerous examples on using this function on the forum. And a few in the manual.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 3, 2022, 12:18pm UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/5 "2022-11-03T12:18:27Z")

</div>

Another solution would be to create a suitable dataset when the template initializes, populated with the correct dates and the rest zeros. Use an editable table to display it. Use the `onCellEdited` function to update the table's dataset as the operator fills it in. Then the Save button would just copy the table dataset property to the template property.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [November 3, 2022, 12:25pm UTC](https://forum.inductiveautomation.com/t/dataset-as-template-parameter/66055/6 "2022-11-03T12:25:36Z")

</div>

save script:

```auto
import json
import re

tabledata = event.source.parent.getComponent('tmp_Rpt_plan').templateParams
data = system.dataset.toPyDataSet(tabledata)
from com.inductiveautomation.factorypmi.application.components import PMINumericTextField
repeater = event.source.parent.getComponent('tmp_Rpt_plan').getLoadedTemplates()
for row, component in enumerate(repeater):
	data = event.source.parent.getComponent('tmp_Rpt_plan').templateParams
	dsUpdate = []
	for subcomponent in component.getComponents():
		if isinstance(subcomponent, PMINumericTextField):
			dsUpdate.append(subcomponent.value)
	event.source.parent.getComponent('tmp_Rpt_plan').templateParams = system.dataset.updateRow(data, row, {'PlanData':dsUpdate[1]})

system.tag.writeBlocking("[client]Plan", tabledata)
jsondata ={}

MachineName ={}

PlanData ={}

MachineID = {}

#tableName ="tbl_productionplan"

childcount = data.getRowCount()

Process = event.source.parent.Process

for a in range(childcount):
	MachineName[a] =data.getValueAt(a,'MachineName')   
	PlanData[a] = data.getValueAt(a,'PlanData')   

MachineID[a] =data.getValueAt(a,'MachineID')   
	
#PlanData={tuple({Day1}),tuple({Day2}),tuple({Day3}),tuple({Day4}),tuple({Day5}),tuple({Day6}),tuple({Day7})}
jsondata = {'Data':{'MachineID':MachineID,'PlanData':PlanData}}

json_data = json.dumps(jsondata)
params ={"iPlanData":jsondata,"iProcess":Process}
system.db.runNamedQuery("Prod_Plan/InsertPlan",params )

```

Let me go through your suggestion
