# Data input via Forms, using Roles to partition user activities.

For a demo example of following steps, here is the policy timestamp: **1675164605.096601003**

## **Objective**

Construct a policy in which one group of users can individually fill in and submit documents for approval and view their own documents’ status, and another group of users can view and take approve/reject actions on any of these user documents.

## **Approach**

1. Assign ‘User’ and ‘Approver’ roles to users to partition them into groups where one can fill in forms and send resulting documents to approvals, and the other group would ‘approve/reject’ these documents.
2. Create schema and necessary policy elements to enable ‘form-filling in and submission’ and ‘approval’ workflows.

## **Preparation**

Create 3 containers which will be responsible for choosing a role, submission and approval documents correspondingly.

Assign these containers to appropriate Permissions: ‘no\_role’, ‘User’, or ‘Approver’, and add the first containers into the **RoleSelectionBlock**.

See detailed information about the Roles in [Example 1](https://guardian.hedera.com/guardian/standard-registry/policies/library-of-policy-examples/creating-and-using-roles).

![Creating Roles and adding RoleSelectionBlock](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-3d400ff51513f018cac09c00df7734a50e5fd6ee%2F0%20\(2\)%20\(1\)%20\(1\).png?alt=media)

## **Main section**

### **Creating the document**

#### 1. Create a schema for Policy data input

1.1 Go to ‘Schemas’ tab and create a new schema

![Creating new Schema](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-be65027b294b185fed7213e6872c199795175223%2F1%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

1.2 To make sure there is some demo/test data content in this schema create 3 fields:

* **Organization name** of type ‘String’
* **Start Date** of type ‘Date’
* **End Date** of type ‘Date’
* **Amount** of type ‘Number to represent the amount of CO2 emissions for the time period (between the ‘Start Date’ and ‘End Date’)

![Creation of 3 fields](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-04a29c57fc31fe32efeb246790febbdf93569f1e%2F2%20\(3\).png?alt=media)

#### 2. To perform data input into the Policy the ‘**requestVcDocumentBlock**’ will be used

2.1 Since the scope of this example includes input of multiple documents the Policy requires logic similar to what is known as ‘loop’ or ‘iteration’.

For this ‘**interfaceStepBlock**’ is required with ‘**Cyclic**’ option enabled. This will allow to return to the initial state after the document was saved.

![InterfaceStepBlock is added as cyclic\_container](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-61ba944fddfe519f3c0763732708bbb704c3413b%2F3%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

2.2 Add ‘**requestVcDocumentBlock**’ into the ‘*cyclic\_container*’

![Adding requestVcDocumentBlock into cyclic\_container](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-ab0bac4778a44be770b19d20fa50e3b60e2d30d0%2F4%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

2.3 Then select the previously created Schema

![Selecting already created Schema](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-466c6c67f39db6e6a44554840a68ce5ae11e615b%2F5%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

2.4 Select ‘New UUID’ to configure automatic generation of unique IDs for each document

![Selecting UUID](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-aadd0c2aa9daefe2cc307b41b02e681d91d8eac0%2F6%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

2.5 By default ‘**requestVcDocumentBlock**’ is displayed as a Form covering the entire page. To prevent this choose ‘**DIALOG**’ value for the field ‘Type’.

![Selecting DIALOG as Type](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-d7f7d2773ff4ea6a3631c067d8f4e23644564807%2F7%20\(2\)%20\(1\)%20\(1\).png?alt=media)

#### 3. Save documents in the Database.

3.1 Add ‘**sendToGuardianBlock**’ into the container ‘*cyclic\_container’* immediately after ‘*create\_new\_document’*

![Adding sendToGuardianBlock in container cyclic\_container](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-8d8f4f7e49494d4147505e85d8b7e178e4657530%2F8%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

3.2 Select data type and where to store the document

![Selecting Data Source and Type](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-606bb40e086be398dd3aca3d8cbec9c29d0f2af5%2F9%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

3.3 Create appropriate attributes to capture/store document status

Add ‘Status’ attribute and set the initial ‘New’ value for new documents

![Adding Status Attribute with New Value](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-d734e3e628cb22a1278f3a688d34a331ea8ef6f7%2F10%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

### **Displaying the documents**

1. To display documents ‘**interfaceDocumentsSourceBlock***’ is used*

1.1 Add ’**interfaceDocumentsSourceBlock***’* into the ‘**user\_roles***’* container

![Adding interfaceDocumentsSourceBlock into user\_roles container](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-6af2c82902d151ceb91b008e058daa501932bfa5%2F11%20\(2\)%20\(1\).png?alt=media)

1.2 Specify the needed columns, their titles and where the values will be taken for display

![Specifying paths, type and titles of the columns](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-2953b8c38d37f35b6cd52219d6d754d0fd9aaa3c%2F12%20\(3\).png?alt=media)

1.3 To retrieve the data from the database ’**documentsSourceAddon***’ block is used*

1.3.1 Add ‘**documentsSourceAddon***’ to the* ‘**user\_grid***’*

![Adding documentsSourceAddon to retrieve data](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-c7d3378bd5282b4f02ef0e58aef2c5083e3bd868%2F13%20\(2\)%20\(1\).png?alt=media)

1.3.2 Select where to retrieve the documents from

![Selecting VC Document](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-a1541bc832294359baf5d487cb8b014836e778ad%2F14%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

1.3.3 Select the schema upon which the selected documents should be based on

![Selecting Schema](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-44655a23be4eb781eb5e9898e7bc27990856888a%2F15%20\(6\).png?alt=media)

1.3.4 Select *‘***Owned by User***’* checkbox which would filter in only the documents that are created by this user (this will disable the ability to view other documents)

![Selecting Owned by User checkbox](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-f9a7bbb68591024ce649e2ba9d69ea3c1472158c%2F16%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

### **Approving the documents**

1. To display documents ‘**interfaceDocumentsSourceBlock***’ is used*

1.1 As in the previous section we added ‘**interfaceDocumentsSourceBlock***’* and configured displayed columns

1.2 Add additional column which would contain the ‘**Approve**’ button

![Adding Approve column](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-16a37cc1ab50e740a6efb1ef9ffb0c63f6118209%2F17%20\(5\).png?alt=media)

1.3 Since the Approve button should be displayed only for new documents use two ‘**documentSourceAddon**’ block

![Adding two documentSourceAddon Blocks](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-681a8cb0539e17723c10e486e4f1da99cf4e7f61%2F18%20\(1\)%20\(2\).png?alt=media)

Configure both ‘**documentSourceAddon**’ blocks similarly to how it was in the previous sections, except here do not select the ‘*Owned by User*’ checkbox to allow the Approvers to see all documents (created by all users)

1.4 Separate the documents by status by means of creating the corresponding filters

![Creating Equal status filter](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-b4d505eba33391cef58ae6ea175395ff2ca197d7%2F19%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\)%20\(1\).png?alt=media)

![Creating not equal status filter](https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-7b6f78886ddb47112e32a4ced61148022b41335b%2F20%20\(3\).png?alt=media)

2. To enable actions (in this example ‘Approve’ and ‘Reject’) the ‘**buttonBlock**’ block is used.

2.1 Best practice is to wrap the ‘**buttonBlock**’ block in a container

Switch off the ‘Default Active’ option to avoid specifying the button as an independent element and hide it

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-fe9fe140a40276456290acb00d69f821456ea020%2FTemplate_2_screenshot_22.png?alt=media" alt=""><figcaption></figcaption></figure>

2.2 Create 2 buttons for ‘Approve’ and ‘Reject’ correspondingly.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-3a7fde89981fd97f1f1239a7e66e8f9167c14d76%2FTemplate_2_screenshot_23.png?alt=media" alt=""><figcaption></figcaption></figure>

2.3 ‘**buttonBlock**’ is responsible only for the actions, in order to save the refreshed status of the documents.

Create 2 ‘**sendToGuardianBlock**’ blocks with the corresponding values for the ‘Status’.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-ab41cba60e74bde6c6dbd6f9bae7894fe83eda8b%2FTemplate_2_screenshot_24.png?alt=media" alt=""><figcaption></figcaption></figure>

2.4 By default blocks are always directly connected to the next block (just below it). To decouple the blocks select ‘**Events**’ tab and switch off the default events for both blocks.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-4c64e62eb48be20882f24a1f39bc2c7dc9b913f2%2FTemplate_2_screenshot_25.png?alt=media" alt=""><figcaption></figcaption></figure>

2.5 Connect events from the ‘**buttonBlock**’ with the corresponding ‘**sendToGuardianBlock***’* by selecting the *Events* tab and create 2 new events.

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-edeb40a66a49620d498bfb09323c0898d06a4243%2FTemplate_2_screenshot_26.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Return to the grid settings and add the created buttons into the previously prepared column

3.1 Set ‘*Type’* to ‘BLOCK’

3.2 Set ‘*Bind Block*’ to the block which we can place into the column

3.3 In order to display the buttons for only new documents set the corresponding value for the ‘*Bind Group'*

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-47e9b27af1d69eb1fc0576c1e93aa1c7c03f823a%2FTemplate_2_screenshot_27.png?alt=media" alt=""><figcaption></figcaption></figure>

## Result

### 1. Choose a role

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-c04cf25ab30478be470de7f0875b56e1cf443bc0%2FTemplate_2_demo_01.png?alt=media" alt=""><figcaption></figcaption></figure>

### 2. Create new document

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-a1e098f37aef36d1b0590b5a3bcb29252d88663c%2FTemplate_2_demo_02.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-2367aceebb6392ad8ca2c8bc14439b8eb20c0ff7%2FTemplate_2_demo_03.png?alt=media" alt=""><figcaption></figcaption></figure>

### 3. Approve

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-9197c4c9cf64e30a7278fdf35b0e51afdbaa3557%2FTemplate_2_demo_04.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1556785885-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNYWPEEAknX9Vki1yV5HY%2Fuploads%2Fgit-blob-f1d0eefd2f62c2e6c96ebdb0c08692ccd17fd2de%2FTemplate_2_demo_05.png?alt=media" alt=""><figcaption></figcaption></figure>
