# Get Started with SAP Cloud Platform workflows
**You will learn**
* How to enable the workflow service and create an instance in your SAP Cloud Platform account
* How to assign the roles you need to develop and use workflow applications
* How to create multitarget application projects for your workflow in the SAP Web IDE.
* How to deploy these projects to the SAP Cloud Platform.
* How to create multitarget application projects for your workflow in the SAP Web IDE.
* How to deploy these projects to the SAP Cloud Platform.
* How to start an instance of the workflow definition that you have defined using a start form
**Prerequisites**
Get a [Trial Account](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/42e7e54590424e65969fced1acd47694.html)
**Step 1: Add a workflow instance**
1. Access your account on [SAP Cloud Platform Trial](https://cockpit.hanatrial.ondemand.com/cockpit/#/home/trial) by choosing Enter Your Trial Account.
2. Go to your trial subaccount. If you have just created your trial account, choose trial from the breadcrumbs.
3. Use your global password to login.
4. Choose Spaces from the left-hand navigation, and then choose dev.
5. Choose Services | Service Marketplace from the left-hand navigation, and search for workflow. ( If it is not available in EU subaccount, try creating a US subaccount. After which add Application runtime, portal, xsuaa)
6. Search for the Workflow service

The Workflow tile displays the service description and the service plan.
6. Choose Instances from the left-hand navigation, then choose New Instance.

7. In the wizard that comes up, leave the data as is and proceed by choosing Next. On the last page,enter my-workflow-instance as the instance name and choose Finish.

**Step 2: Create role collection**
1. Go back to your trial subaccount by choosing trial from the breadcrumbs.
2. From the left-hand navigation, choose Security | Role Collections, then choose New Role Collection.

3. Enter wfs as the name for your role collection, then choose Save.
4. After the role collection is created, click its name and choose Add Role.
5. In the wizard that comes up, select workflow!b1774 in the field Application Identifier. Add the following roles one by one:
WorkflowAdmin
WorkflowDeveloper
WorkflowInitiator
WorkflowParticipant
WorkflowViewer
**Step 3: Assign role collection**
1. Go back to your trial subaccount by choosing the trial from the breadcrumbs.
2. From the left-hand navigation, choose Security | Trust Configuration, then click SAP ID Service.

3. Enter your email address, then choose Show Assignments.

4. Choose Add User.
5. Choose Assign Role Collection, and select the wfs collection that you created before. Then choose Assign Role Collection again.

**Step 4: Enable the workflow extension and Cloud Foundry**
1. In your web browser, open the cockpit of [SAP Cloud Platform Trial](https://cockpit.hanatrial.ondemand.com/cockpit/#/home/trial).
2. Choose Launch SAP Web IDE.

3. In the navigation area of SAP Web IDE, choose the Preferences icon.
4. Select Extensions, and search for workflow.
5. Toggle the switch of the Workflow Editor extension, choose Save and then Refresh.

6. Switch to the Cloud Foundry preference.
7. Enter your API endpoint, and select the organization and space from the respective dropdowns.
8. Save your changes.
In the credentials popup, enter your trial user email and password.

**Step 5: Create an SAP Fiori launchpad project**
1. In the navigation area of SAP Web IDE, choose the Development icon.
2. Select the Show hidden files icon to display hidden files.

3. Under Files, right-click Workspace and choose New | New Project from Sample Application.

4. In the wizard, set Category to Workflow Sample Application and select the Workflow Applications on SAP Fiori Launchpad for Cloud Foundry (Trial) template. Then choose Next.

5. Select the checkbox and provide your consent to create the application, and choose Finish.

You now see a project with an mta.yaml file in your workspace:

If there are layout issues with the editor window (can’t see the properties), simply refresh the SAP Web IDE window (F5).
**Step 6: Use existing workflow instance project**
You can directly copy the following code snippet for mta.yaml file or you can follow next steps to get the mta as shown in snippet.
```
ID: sample.workflowtiles.mta.trial
_schema-version: '2.1'
parameters:
deploy_mode: html5-repo
version: 0.0.1
modules:
- name: workflowtilesApprouter
type: approuter.nodejs
path: workflowtilesApprouter
parameters:
disk-quota: 256M
memory: 256M
requires:
- name: workflowtiles_html5_repo_runtime
- name: portal_resources_workflowtiles
- name: uaa_workflowtiles
- name: my-workflow-instance
- name: workflowtilesFLP
type: com.sap.portal.content
path: workflowtilesFLP
parameters:
stack: cflinuxfs3
memory: 512M
buildpack: 'https://github.com/cloudfoundry/nodejs-buildpack/releases/download/v1.6.39/nodejs-buildpack-cflinuxfs3-v1.6.39.zip'
requires:
- name: portal_resources_workflowtiles
- name: uaa_workflowtiles
- name: my-workflow-instance
resources:
- name: workflowtiles_html5_repo_runtime
parameters:
service-plan: app-runtime
service: html5-apps-repo
type: org.cloudfoundry.managed-service
- name: portal_resources_workflowtiles
parameters:
service-plan: standard
service: portal
type: org.cloudfoundry.managed-service
- name: uaa_workflowtiles
parameters:
path: ./xs-security.json
service-plan: application
service: xsuaa
type: org.cloudfoundry.managed-service
- name: my-workflow-instance
type: org.cloudfoundry.existing-service
```
1. In your workspace in the sample.trial project, right-click the mta.yaml file and choose Open MTA Editor.

2. On the Resources tab, replace the workflow resource. On the left-hand side, select workflow_workflowtiles and change it to my-workflow-instance. Choose org.cloudfoundry.existing-service in the Type field.

3. Save your changes.
4. Switch to the Modules tab, and select workflowtilesApprouter. Under Requires replace one of the uaa_workflowtiles (resource) entries with a my-workflow-instance (resource) resource entry.

To really ensure that the updated instance name is used in all respective places, execute the following steps:
* 1. Select the workflowtilesFLP module and under Requires switch the my-workflow-instance (resource) entry to some other entry.
* 2. Save your changes.
* 3. Switch the changed resource entry back to my-workflow-instance (resource).
* 4. Save your changes.
**Step 7: Build and deploy your launchpad project**
1. Right-click your sample.workflowtiles.mta.trial project in the workspace, and choose Build | Build with Cloud MTA Build Tool (recommended).

console shows the status of the build: Build of sample.workflowtiles.mta.trial completed.
2. Open the mta_archives folder.
3. Right-click your .mtar file, and choose Deploy | Deploy to SAP Cloud Platform.

4. Enter your API endpoint, and choose Deploy.

**Step 8: Access your SAP Fiori launchpad apps**
1. Open the SAP Web IDE console, and search for the launchpad URL https://<dev space name>-trial-dev- workflowtilesapprouter.cfapps.<your endoint>.hana.ondemand.com.

2. Copy the URL to your browser.
If the URL does not work, append /cp.portal to it.
3. Log on to your trial account by entering your email address and password. Your home page of SAP Fiori launchpad is displayed.

**Step 9: Create a workflow project**
1. In the navigation area of SAP Web IDE, choose the Development icon.
2. Under Files, right-click Workspace and choose New | Project from Template.

3. In the wizard, set Environment to Cloud Foundry and select the Multi-Target Application template. Then choose Next.

4. Enter a name for the new workflow project, for example, MyWorkflowProject, and choose Next.

5. Do not select Use HTML5 Application Repository, and choose Finish.

You now see a project with an mta.yaml file in your workspace:

If there are layout issues with the editor window (can’t see the properties), simply refresh the SAP Web IDE window (F5).
**Step 10: Create a workflow module**
1. Select and right-click your project, then choose New | Workflow Module.

2. Enter the name MyWorkflow, then choose Next.

3. Enter the workflow name ApprovalWorkflow, then choose Finish.

You now see your new workflow:

**Step 11: Adapt the MTA Workflow project**
1. In your workspace under MyWorkflowProject, right-click the mta.yaml file and choose Open MTA Editor.

Or you can copy paste the following code snippet too.
```
ID: MyWorkflowProject1
_schema-version: '2.1'
parameters:
deploy_mode: html5-repo
version: 0.0.1
modules:
- name: MyWorkflowProject1_appRouter
type: approuter.nodejs
path: MyWorkflowProject1_appRouter
parameters:
disk-quota: 256M
memory: 256M
requires:
- name: MyWorkflowProject1_html5_repo_runtime
- name: MyWorkflowProject1_ui_deployer
type: com.sap.html5.application-content
path: MyWorkflowProject1_ui_deployer
requires:
- name: MyWorkflowProject1_html5_repo_host
- name: MyWorkflow
type: com.sap.application.content
path: MyWorkflow
requires:
- name: my-workflow-instance
parameters:
content-target: true
resources:
- name: MyWorkflowProject1_html5_repo_runtime
parameters:
service-plan: app-runtime
service: html5-apps-repo
type: org.cloudfoundry.managed-service
- name: MyWorkflowProject1_html5_repo_host
parameters:
service-plan: app-host
service: html5-apps-repo
type: org.cloudfoundry.managed-service
- name: my-workflow-instance
type: org.cloudfoundry.existing-service
```
2. Switch to the Resources tab, and change the name from workflow_MyWorkflowProject to my-workflow- instance, and under Type, select org.cloudfoundry.existing-service. Then change the service plan value to lite.

3. On the Modules tab, check that my-workflow-instance (resource) is listed under Requires.

4. Save your changes.
**Step 12: Create task form**
1. In your workspace, choose MyWorkflowProject | MyWorkflow | workflows. Then double-click the ApprovalWorkflow.workflow file.

2. To create a user task in the editor, select StartEvent1 and then from the speedbuttons choose User Task .

3. Make sure to select the newly created user task. Otherwise, the User Task Properties are not displayed.
4. Under User Task Properties | USER INTERFACE, set the Type to Form.

5. Under Form Details, select Create File.

6. In the popup, enter the following data, then choose Create:
| Field | Value |
| -------- | -------- |
| Name | ApprovalForm |
| Revision | 1.0 |

A message confirms that the form has been created.
**Step 13: Add fields to your task form**
1. In the form editor (for the ApprovalForm.form), select the Fields section.
2. To add two new fields, click Add Field twice, and enter the following data to define the fields:
| Label/Title | Type | Context Path |
| -------- | -------- | -------- |
| Title | String |${context.product}|
| Price | Float |${context.price}|

3. Save your changes.
**Step 14: Add approve and reject buttons**
1. In the form editor (for the ApprovalForm.form), select the Decisions section.
2. To add two new buttons, click Add twice.
3. In the two new rows that are added in the Decisions section, enter the following data:
| Text | ID | Type |
| -------- | -------- | -------- |
| Approve | approve | Positive |
| Reject | reject | Negative |

4. Save your changes.
**Step 15: Complete the user task**
1. Go back to the ApprovalWorkflow.workflow file. If you have closed it, reopen it by selecting and choosing Workflow Editor.
2. Under User Task Properties | GENERAL, enter ApproveBook in the Name field.

3. Switch to the DETAILS tab, and enter Approval in the Subject field.

4. Under Recipients, enter your email address in the Users field.

5. Save your changes.
**Step 16: Build the workflow project**
1. Build the MyWorkflowProject project by right-clicking it and choosing Build | Build with Cloud MTA Build Tool (recommended).

You will receive a build confirmation popup.
2. In your workspace from the mta_archives folder, right-click the MyWorkflowProject_0_0_1.mtar file and choose Deploy | Deploy to SAP Cloud Platform.

3. In the popup, select your API endpoint, organization, and space.
4. Choose Deploy.

You will receive a deploy confirmation popup.
**Step 17: Open the Workflow Monitor - Workflow Definitions app**
1. Open your browser and access your SAP Fiori launchpad at: https://<dev space name>-trial-dev-workflowtilesapprouter.cfapps.<your endoint>.hana.ondemand.com.
2. Choose the Workflow Monitor - Workflow Definitions tile, and for the ApprovalWorkflow task choose Start New Instance.

3. Leave the JSON context as is, and choose Start New Instance.

4. Go back to the Home page. The My Inbox app displays one task.

5. Open My Inbox, and choose Approve to process the task.

*Congratulations! You have successfully created your first workflow in SAP cloud platform.*