# Running Stage(s)

The core of your device logic can be divided into different parts through its lifecycle. We can use multiple running stages to partition the device simulation into logical segments.&#x20;

For Example, if we are trying to simulate a smart lock, we could have a **booting** stage that simulates how the device behaves when being switched on, then we could have an **online** stage that defines how the device behaves under normal working conditions and finally we could have an **offline** stage which simulates how the device would behave without a network condition and so on.

Partitioning the device logic into multiple such stages makes it easier for others to understand the device logic and also help while troubleshooting any issues that may arise while running a functional test for the device. There is no limit to the number of such stages that can be created. Let's see how to work with these different stages.

![](/files/RTVBzFnQDPA7dRvHAsKQ)

To add a new stage to the Device Model, move your mouse over the line between the stages where you want to add the new stage, a plus button will appear. On clicking this plus button, a new stage will be created. A new stage can be created anywhere between the Init and the Finished stages, but not outside them.

![](/files/x2rKFHyohej1Dbq41Yzc)

To rename any of the stages, click on their names, a text field will appear and you can rename the stages.

![](/files/ywkgYQo9Vvcid2pannVl)

To delete any stage, move your mouse to the icon above the stage you want to delete, a cross icon will appear. On clicking the cross icon, the stage will be deleted.

![](/files/Qx0cRLMdlBabT4BfGm4T)

To transition to another stage from a given stage use the **next()** function. If the next() function takes the name of any stage as the parameter. If no parameter is supplied to the next() function it will transition to the next stage on the timeline.

```javascript
{
    let serial = glob.get('serial_' + client());
    if (!serial)
    {
        serial = chance.guid();
        glob.set('serial_' + client(), serial);
    }
    state.serial = serial;  
  
    next() //Transitions to the next stage on the timeline
    //Or
    next("Other_Stage") //Transitions to the given stage
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iotify.io/concepts/understanding-a-test/stages-management/running-stage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
