# Give Components a Script at runtime

**URL:** <https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [October 10, 2023, 7:44am UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258 "2023-10-10T07:44:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tjark\_Sterk](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@Tjark\_Sterk](https://forum.inductiveautomation.com/u/Tjark_Sterk)\
**Post date:** [October 10, 2023, 7:44am UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258/1 "2023-10-10T07:44:51Z")

</div>

Hey pretty weird question but is it possible to give a component a script at runtime?  
I know that I can create a new component with the .addComponent() function but I was wondering if i can assign a script to it at runtime.  
Thanks

---

<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:** [October 10, 2023, 1:02pm UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258/2 "2023-10-10T13:02:56Z")

</div>

Yes, but really far under the hood in the module development SDK. (And not documented there, either.)

The supported way to dynamically add/remove components in Vision is with the Template Repeater and the Template Canvas. Using `.addComponent` yourself is fraught with complications.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 10, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258/3 "2023-10-10T13:37:31Z")

</div>

What's your actual use case? What are you trying to do?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 11, 2023, 12:40am UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258/4 "2023-10-11T00:40:51Z")

</div>

> [@pturmel](#):
>
> with the Template Repeater and the Template Canvas

I want to reiterate this because this is more than likely the solution you are looking for. With this approach, you can set your components up in a template already scripted and already set up exactly how you want. Then, you can add or remove them by simply adding rows to or removing rows from a single dataset parameter. It's simple, and perhaps more importantly, it's easily maintainable by others who will someday have to work on the project.

---

<div class="post-metadata">

**Author:** ![Tjark\_Sterk](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@Tjark\_Sterk](https://forum.inductiveautomation.com/u/Tjark_Sterk)\
**Post date:** [October 11, 2023, 7:19am UTC](https://forum.inductiveautomation.com/t/give-components-a-script-at-runtime/80258/5 "2023-10-11T07:19:24Z")

</div>

Yes I will thing about that approach. You actually gave me the information I was missing in another topic ([Dynamically getting a Component by clicking on it - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/dynamically-getting-a-component-by-clicking-on-it/80256)) I posted Yesterday so thanks again. I find it really helpful to know how the stuff is handled in the backend.
