# Creating a Run User account by Analysis

**URL:** <https://community.tago.io/t/creating-a-run-user-account-by-analysis/779>\
**Category:** Tutorials\
**Tags:** tutorials\
**Created:** [January 22, 2022, 7:46pm UTC](https://community.tago.io/t/creating-a-run-user-account-by-analysis/779 "2022-01-22T19:46:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex034/user_avatar/community.tago.io/system/32/24_2.png) [@system](https://community.tago.io/u/system)\
**Post date:** [January 22, 2022, 7:46pm UTC](https://community.tago.io/t/creating-a-run-user-account-by-analysis/779/1 "2022-01-22T19:46:13Z")

</div>

@Filipe da Silva de Oliveira

Hello everyone.

In this tutorial, I’ll explain how to create a run user account by analysis, as well as how to build an input form widget to achieve just that. Creating a run user account by analysis is a very powerful tool when it’s necessary to force some parameters in a fixed time and date format. Also, you can include it externally from TagoIO and adapt it to your application’s needs.

For creating the Analysis you have two options using [TagoIO’s SDK](https://js.sdk.tago.io/):

- The run user’s account will be activated once it is created as it will use your admin’s account token.
- Or, through the other option, once the run user is created they will have to activate it through a confirmation email.

If you want to skip this tutorial and simply use the Analysis and Dashboard templates, they are right here:

- [Analysis template for active run user account](https://admin.tago.io/template/61bc84f9b098a900183d7e2b)
- [Analysis template for deactivated run user account](https://admin.tago.io/template/61bc99dbb205c10019c83d94)
- [Dashboard template](https://admin.tago.io/template/61bc83816b98b00019c149d3)

What are the requirements for this tutorial?

- A Device and Dashboard created for the Input Form Widget.
- An account token with a valid expire time for the analysis that creates activated users.

* * *

#### Creating the Analysis for Activated Users

First, go to the [Analysis](https://admin.tago.io/analysis) menu and click to add a new empty analysis.  
 ![creatingAnalysis](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/77af590f47c4223f9960bb7642ffb37082171e8a.gif)

Then you can copy and paste the following code:

```javascript
    const { Analysis, Account, Utils } = require("@tago-io/sdk");
    
    async function myAnalysis(context, scope) {
      if (!Array.isArray(scope) || scope.length < 7) {
        throw "Scope is missing"; 
      }
    
      const [email, name, password, company, language, date_format, time_format] = scope;
      const environment = Utils.envToJson(context.environment);
      if (!environment.runUrl || !environment.timezone || !environment.accountToken) {
        throw "Environment is missing";
      }
    
      const data = {
        active: true,
        email: email.value,
        name: name.value,
        password: password.value,
        company: company.value,
        language: language.value,
        options: {
          date_format: date_format.value,
          time_format: time_format.value,
        },
        timezone: environment.timezone
      };
    
      try {
        const account = new Account({ token: environment.accountToken });
        await account.run.userCreate(data);
      } catch (ex) {
        context.log(ex);
      }
    }
    
    module.exports = new Analysis(myAnalysis);

```

Now you have to write the environment variables used for this Analysis: the _`runUrl`_, the _`timezone`_, and the _`accountToken`_. To do that, simply go to the Environment tab and write it all down like in the following example:

 ![Captura de tela de 2021-12-17 11-21-37](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/31eb0222853544d45adef6b9004d4ded45bc5b03.png)

From the TagoIO’s run URL, you’ll need to remove the “HTTPS”. For example:

My URL is **[https://61423ee4495a0a001a7f5edd.run.tago.io](https://61423ee4495a0a001a7f5edd.run.tago.io)**, so then when writing it down in the Analysis, I have to remove the HTTPS and it becomes: **[61423ee4495a0a001a7f5edd.run.tago.io](http://61423ee4495a0a001a7f5edd.run.tago.io)**.

You can see that the timezone for these accounts has been fixed in the code. In this tutorial, I will be fixing it in **UTC** but you can use **America/New\_York, America/Chicago, America/Mexico\_City, America/Sao\_Paulo, Europe/London** , and more.

After the analysis is created, click on the **save button** , and let’s start to create the input form that will send all the necessary fields for this Analysis.

* * *

#### Creating the Input Form

The input form will take the user’s data information and trigger the analysis so it can create the account. First of all, we need to add the required fields described [here](https://js.sdk.tago.io/interfaces/Types.RunUser.Device.RunUserCreateInfo.html) **(email, name, password)**; all other fields are optional when creating an account, but for this tutorial we are going to add fields for the company, language, date and time format.

**The timezone is also a required field but was fixed in the Analysis code, and you are able to adapt it as you wish**

![CreatingInputForm](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/02df398f9c169554c0f00bf4bb7c61a9b72a6d43.gif)

Start to create the email field, and it should look something like this, with the **single option checked**.

 ![Captura de tela de 2021-12-17 11-37-36](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/6f0174b64c7347693daf8f727626ef0e69f8ede1.png)

Then create the others: name (text field), password (password field), and company (text field). For the dropdown fields like **language, date format, and time format, you have to give options that are accepted by TagoIO. You can not include a date format that we don’t have the option for.** Because of that, I suggest you use the following options:

#### Language dropdown field

 ![Captura de tela de 2021-12-17 10-30-25](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/49d108549e0fcdb4fdf528ce74d5aade3a72a4c8.png)

#### Date format dropdown field

 ![Captura de tela de 2021-12-17 10-31-11](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/b3ecc209e23caa616d98f7b73f7c454113d89611.png)

#### Time format dropdown field

 ![Captura de tela de 2021-12-17 11-37-48](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/2d3165c6bf0fc6c9a43e31f0bcf4213a2871861a.png)

After creating the fields, you have to configure the submit button so it doesn’t send this data to the bucket and trigger our analysis created earlier.  
 ![creatinInputFormSubmit](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/1X/bae1aadeda97138daeb0c7020d3b7562b42afda0.gif)

Now that everything is successfully created, you can check that when you submit the form with at least the required fields filled out, a new run user will be created in the [User Management](https://admin.tago.io/usermanagement) menu. This input form can also be embedded, and you can use it on your website.

* * *

#### Creating Analysis for Deactivated Users

Just like the other analysis, you can create a new one and copy-paste the following code:

```javascript
    const { Analysis, RunUser, Utils } = require("@tago-io/sdk");
    
    
    async function myAnalysis(context, scope) {
      if (!Array.isArray(scope) || scope.length < 7) {
        throw "Scope is missing"; 
      }
      
      const [email, name, password, company, language, date_format, time_format] = scope;
      const environment = Utils.envToJson(context.environment);
      if (!environment.runUrl || !environment.timezone) {
        throw "Environment is missing";
      }
    
      const data = {
        active: true,
        email: email.value,
        name: name.value,
        password: password.value,
        company: company.value,
        language: language.value,
        options: {
          date_format: date_format.value,
          time_format: time_format.value,
        },
        timezone: environment.timezone
      };
      
      try {
        await RunUser.create(environment.runUrl, data);
      } catch (ex) {
        context.log(ex);
      }
    }
    
    module.exports = new Analysis(myAnalysis);

```

This time only two environment variables are used: _`runUrl`_ and _`timezone`_. Simply fill them out with the desired data, and save.

* * *

I hope this helps with your application! Stay tuned to this community to learn more awesome things.

Regards,  
Filipe.
