# Need to execute the script when it entered the perspective page

**URL:** <https://forum.inductiveautomation.com/t/need-to-execute-the-script-when-it-entered-the-perspective-page/90852>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [May 24, 2024, 7:03am UTC](https://forum.inductiveautomation.com/t/need-to-execute-the-script-when-it-entered-the-perspective-page/90852 "2024-05-24T07:03:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivasan\_s](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@srinivasan\_s](https://forum.inductiveautomation.com/u/srinivasan_s)\
**Post date:** [May 24, 2024, 7:03am UTC](https://forum.inductiveautomation.com/t/need-to-execute-the-script-when-it-entered-the-perspective-page/90852/1 "2024-05-24T07:03:42Z")

</div>

I need to execute the following script when enterted into the view/page,

```python
	i=self.view.params.row_id
	query = "SELECT name, drawingno, product FROM drawing_master WHERE id = ?"
	params = [i]
	result = system.db.runPrepQuery(query, params)
	if result:
		row = result[0] # Assuming only one row is fetched
	   	column1_value = row["name"]
		column2_value = row["drawingno"]
		column3_value = row["product"]
		self.parent.parent.getChild("FlexContainer_0").getChild("Name_text").props.text = column1_value
		self.parent.parent.getChild("FlexContainer_0").getChild("drawing_no_text").props.text = column2_value 
		self.parent.parent.getChild("FlexContainer_1").getChild("TextField").props.text = column3_value
	

```

When I click the one button in page A it will navigates me to Page B. When Enterted into the Page B , need to runs this script. Kindly help me on this. I was really stuck!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 24, 2024, 7:32am UTC](https://forum.inductiveautomation.com/t/need-to-execute-the-script-when-it-entered-the-perspective-page/90852/2 "2024-05-24T07:32:44Z")

</div>

Here's one way.

1. Add a parameter `row_id` onto view B.
2. When the button is pressed on A then navigate to view B and pass in the row\_id.
3. On view B create three custop props; `custom.name`, `custom.drawingno` and `custom.product`.
4. Right-click on view B → Configure Events ... → onStartup → Script.

```python
	query = "SELECT name, drawingno, product FROM drawing_master WHERE id = ?"
	params = [self.view.params.row_id]
	result = system.db.runPrepQuery(query, params)
	if result:
		row = result[0] # Assuming only one row is fetched
	   	self.custom.name = row["name"]
		self.custom.drawingno = row["drawingno"]
		self.custom.product = row["product"]

```

1. Create property bindings from your components to the custom properties. Make them bidirectional.

Now you have eliminated all the parent.parent.getChild().getChild() stuff and it won't break if you move components in or out of containers.

---

<div class="post-metadata">

**Author:** ![srinivasan\_s](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@srinivasan\_s](https://forum.inductiveautomation.com/u/srinivasan_s)\
**Post date:** [May 24, 2024, 8:35am UTC](https://forum.inductiveautomation.com/t/need-to-execute-the-script-when-it-entered-the-perspective-page/90852/3 "2024-05-24T08:35:20Z")

</div>

Thankyou, Noted!
