# 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://docs.guardianservice.io/technical-information/library-of-policy-examples/creating-and-using-roles).

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FMDulWIMj9y0VI5xj5CMf%2Fimage.png?alt=media&#x26;token=a4399642-b3e1-4205-8fe0-ce2ef73a9b8e" alt=""><figcaption></figcaption></figure>

### **Main section**

#### **Creating the document**

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

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FKelpw4gE0MDSIFg6KvSS%2Fimage.png?alt=media&#x26;token=c674afdf-6dd4-4716-9e0b-dccabfc6c48d" alt=""><figcaption></figcaption></figure>

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’)

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FC2pXGVMUzo7mRtnieirA%2Fimage.png?alt=media&#x26;token=3406493a-00e1-457d-a73e-9a68ece2de4c" alt=""><figcaption></figcaption></figure>

**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.

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FTJWdXjWy23Ttm5LKFgrR%2Fimage.png?alt=media&#x26;token=b65e9f12-e2d8-4247-b473-5418ac67b0b0" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FrXzqL2fGGGbsxwtwthVa%2Fimage.png?alt=media&#x26;token=cf56ebd7-537d-4ce4-ae23-8b7e25db399f" alt=""><figcaption></figcaption></figure>

2.3 Then select the previously created Schema

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FOvwroBOWrTYYE6IDtYjj%2Fimage.png?alt=media&#x26;token=40b6973f-8f46-4c18-a611-c0671242519c" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2F7uErcnjIoKag8RxpOKuu%2Fimage.png?alt=media&#x26;token=8dd385c5-79f0-45c9-8876-bdd4c472c841" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FZBDRGJ2hqbWN9W2VbOMs%2Fimage.png?alt=media&#x26;token=3801924c-165f-4432-a0ba-a8aebae3614c" alt=""><figcaption></figcaption></figure>

**3. Save documents in the Database.**

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FYrlcaEep6uVBIhUVohzQ%2Fimage.png?alt=media&#x26;token=27564757-7b49-4b9a-ba2e-9275b5f4ce6b" alt=""><figcaption></figcaption></figure>

3.2 Select data type and where to store the document

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FlPA7rB0QPTWlmHbpHxpi%2Fimage.png?alt=media&#x26;token=c7720c9a-33ac-4611-bd93-1ffd65070c85" alt=""><figcaption></figcaption></figure>

3.3 Create appropriate attributes to capture/store document status

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2F8yH2KVXebWJ4D192WLsT%2Fimage.png?alt=media&#x26;token=aaf5cae1-1f4b-477e-9acc-57b878a89749" alt=""><figcaption></figcaption></figure>

#### **Displaying the documents**

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

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FzCym1sNZzA0YJ01hCok2%2Fimage.png?alt=media&#x26;token=32b17afa-72e6-4a3e-8d9b-879a5e892b29" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FX05jhWmiGKASuarkXEk8%2Fimage.png?alt=media&#x26;token=73f7832c-87bb-4208-8038-418e733ed46c" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2F9QpuV3OMgUrgN5prUlgM%2Fimage.png?alt=media&#x26;token=f4eef588-6993-43cb-93b5-f12943e3b768" alt=""><figcaption></figcaption></figure>

1.3.2 Select where to retrieve the documents from

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FrsctNcTH1pk8pNkAxWrZ%2Fimage.png?alt=media&#x26;token=be230f35-d999-42f3-a8ec-e6137168494b" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2Fo0IIf2dtW199TpReVLXi%2Fimage.png?alt=media&#x26;token=2b956524-f382-4e7a-91c8-3590688e0507" alt=""><figcaption></figcaption></figure>

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)

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FbsyvsjJxfR35v4LeZEx4%2Fimage.png?alt=media&#x26;token=eb0874b9-08fa-456a-84ed-19cc1073bdb0" alt=""><figcaption></figcaption></figure>

#### **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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2Ftxz63i4LUcWW1dTWPtxH%2Fimage.png?alt=media&#x26;token=5bbec23c-84e8-4362-a4a6-504532c1d046" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FOdeRalfYr7SGCjOvfglH%2Fimage.png?alt=media&#x26;token=9f3e9971-1298-4235-935f-fc6cd7fb15cc" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2F1PnodHaKdBA0gAw0cDej%2Fimage.png?alt=media&#x26;token=63d7bdd8-8a95-4b88-99ef-2298505f3b42" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FZgcm6TdpVG3UmG0D5H2l%2Fimage.png?alt=media&#x26;token=fcdaa6d8-79d2-4150-8624-8d56821f56ca" alt=""><figcaption></figcaption></figure>

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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2Fk3XBOjhNB3hReHSJGlXW%2Fimage.png?alt=media&#x26;token=959220db-b421-48bd-93e5-7e30d0490ef0" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2Ft2ciLCjkYIvKdC1p1EOy%2Fimage.png?alt=media&#x26;token=63537959-aff3-49f7-a7a3-6f460eabb3a5" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FPesxaweFxaJkYfSW6BSU%2Fimage.png?alt=media&#x26;token=a5b56363-78ea-47e1-91dc-45228517a8a4" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2Fa3K9wc7ksGsKcuw7jrhB%2Fimage.png?alt=media&#x26;token=14f69cc8-cb14-44db-a961-2ab3cb7540ff" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FoeqZ9egofrrGZOsloozo%2Fimage.png?alt=media&#x26;token=37064f88-4912-49a1-941c-d263959ad957" 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://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FZS1uVTqrBaerQizg1dK1%2Fimage.png?alt=media&#x26;token=53e9473e-e67a-496a-a56d-d73e93447d5e" alt=""><figcaption></figcaption></figure>

### Result

#### 1. Choose a role

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FlcnVJqM4RObBM9RKgVod%2Fimage.png?alt=media&#x26;token=8dc88147-4da8-458c-a081-9d4e506d1455" alt=""><figcaption></figcaption></figure>

#### 2. Create new document

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FPOg5rJLzLQar4nqCdOLz%2Fimage.png?alt=media&#x26;token=efce3872-4b2b-4a85-b988-fa0466163b81" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FdQbaVS9Uz6IydBofuVbZ%2Fimage.png?alt=media&#x26;token=c5813984-4ea1-44c6-aa40-410639284fa1" alt=""><figcaption></figcaption></figure>

#### 3. Approve

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2FzPsebcHqSHUAPAADOIds%2Fimage.png?alt=media&#x26;token=ebe208b0-7761-47f9-aa04-a57151a6c9e8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3006114282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVOaWpJKxLZf1Tee9eCO%2Fuploads%2F0dQe3KJzr63ZucDdXMC7%2Fimage.png?alt=media&#x26;token=8a64f874-eb34-4bd9-aac7-7c33073be51a" alt=""><figcaption></figcaption></figure>
