
Since I need multiple scopes, I have prepared the following file named "authorities.json" (the name can be anything).
{
"authorities": [
"WORKFLOW_INSTANCE_START",
"WORKFLOW_INSTANCE_GET_CONTEXT",
"WORKFLOW_INSTANCE_GET",
"TASK_GET",
"TASK_COMPLETE",
"TASK_UPDATE"
]
}Next, execute the following command to create a service instance. The file prepared in the above step is used to provide parameters to the instance. "wf_cloud_sdk" is the name of the service instance. Again, you can chose your preferred name.
cf create-service workflow lite wf_cloud_sdk -c authorities.jsoncf update-service wf_cloud_sdk -c authorities.jsoncf create-service-key wf_cloud_sdk key1cf service-key wf_cloud_sdk key1{
"content_endpoint": "https://api.workflow-sap.cfapps.eu10.hana.ondemand.com/workflow-deploy/rest/internal/v1",
"endpoints": {
"workflow_odata_url": "https://api.workflow-sap.cfapps.eu10.hana.ondemand.com/workflow-service/odata",
"workflow_rest_url": "https://api.workflow-sap.cfapps.eu10.hana.ondemand.com/workflow-service/rest"
},
"html5-apps-repo": {
"app_host_id": "1365363a-6e04-4f43-876a-67b81f32306e,1a5b93af-f1af-4acf-aee0-8c6cc8d3f315,8964e911-e35d-4cfd-972e-08e681a2df0f,9ea7410f-80ea-4b19-bbf0-4fca238ef098"
},
"portal_content_provider": {
"instance_id": "b87e14b7-ea72-4866-80b7-fe284e75e83a"
},
"saasregistryappname": "workflow",
"sap.cloud.service": "com.sap.bpm.workflow",
"uaa": {
"apiurl": "https://api.authentication.eu10.hana.ondemand.com",
"clientid": "xxxxxxxxxx",
"clientsecret": "xxxxxxxxxx",
"credential-type": "binding-secret",
"identityzone": "b736177ctrial",
"identityzoneid": "cf4bec0f-ec63-4d37-8efd-ded0e8f33c58",
"sburl": "https://internal-xsuaa.authentication.eu10.hana.ondemand.com",
"subaccountid": "cf4bec0f-ec63-4d37-8efd-ded0e8f33c58",
"tenantid": "cf4bec0f-ec63-4d37-8efd-ded0e8f33c58",
"tenantmode": "dedicated",
"uaadomain": "authentication.eu10.hana.ondemand.com",
"url": "https://b736177ctrial.authentication.eu10.hana.ondemand.com",
"verificationkey": "-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxfwBi8D8tOJ61KJ8PJel0ML3oUt+A7k7r7F9gpUAAMon5wqS018oOWErn3gU8VwLCrtDiz9ow8aiia5gxvKXSyMIulMUK/H5QaLMPDFmlPG8hwFR8c3KbxwbzvY4gase7B4Gi2YS6eii+7sNejCbz8tFzpOJJbxia6VX7JCuhs463vFA1svPFDE7Ewa6A5mdpP/uRpW1FQC4zL2npN9dH3T/Osp6b30EKPzL2WcsNes8stxcC8xkMGHDZSBCiAUMhCseD0eei3cwCOMzZj92agyUQiIBr1qgXjIOz8W3xlimkEmRTW8xNlTp7jO972plK1nlVYNnvfA2ObE7cOSqYwIDAQAB-----END PUBLIC KEY-----",
"xsappname": "clone-52964022-f257-4e19-a621-463a969e3e70!b54386|workflow!b10150",
"zoneid": "cf4bec0f-ec63-4d37-8efd-ded0e8f33c58"
}
}workflow_rest_urlclientidclientsecreturl appended by /oauth/token?grant_type=client_credentials
sap-cloud-sdk init wf_cloud_sdknest generate module workflow
nest generate controller workflow
nest generate service workflow
@Sisn/cloud-sdk-workflow-service-cf to dependency of your project.npm install @sap/cloud-sdk-workflow-service-cfsrc/workflow/workflow.service.ts and add the following code. These methods will be called from the controller which we'll implement in the next step. See only a minimal lines of code is required for executing each API.import { Injectable } from '@nestjs/common';
import {
WorkflowInstance,
WorkflowInstancesApi,
UserTaskInstancesApi,
TaskInstance,
} from '@sap/cloud-sdk-workflow-service-cf';
@Injectable()
export class WorkflowService {
private destination = { destinationName: 'Workflow-Api' };
startWorkflow(definitionId: string, body: any): Promise<WorkflowInstance> {
return WorkflowInstancesApi.startInstance({
definitionId: definitionId,
context: body,
}).execute(this.destination);
}
getWorkflowInstances(definitionId: string): Promise<WorkflowInstance[]> {
return WorkflowInstancesApi.queryInstances({
definitionId: definitionId ? definitionId : '',
$top: 10,
$orderby: 'startedAt desc',
}).execute(this.destination);
}
getWorkflowInstance(workflowInstanceID: string): Promise<WorkflowInstance> {
return WorkflowInstancesApi.getInstance(workflowInstanceID).execute(
this.destination,
);
}
getWorkflowContext(workflowInstanceID: string): Promise<any> {
return WorkflowInstancesApi.getInstanceContext(workflowInstanceID).execute(
this.destination,
);
}
getUserTasks(workflowInstanceID: string): Promise<TaskInstance[]> {
return UserTaskInstancesApi.queryInstances({
workflowInstanceId: workflowInstanceID,
}).execute(this.destination);
}
updateUserTask(taskInstanceID: string, body: any): Promise<void> {
return UserTaskInstancesApi.updateInstance(taskInstanceID, {
context: body,
status: 'COMPLETED',
}).execute(this.destination);
}
}
src/workflow/workflow.controller.ts and add the following code.import {
Body,
Controller,
Get,
HttpCode,
Param,
Patch,
Post,
Query,
} from '@nestjs/common';
import { WorkflowService } from './workflow.service';
import {
TaskInstance,
WorkflowInstance,
} from '@sap/cloud-sdk-workflow-service-cf';
@Controller('workflow')
export class WorkflowController {
constructor(private readonly workflowService: WorkflowService) {}
@Post('/instance/:definitionId')
@HttpCode(201)
startWorkflow(
@Body() body,
@Param('definitionId') definitionId,
😞 Promise<WorkflowInstance> {
return this.workflowService.startWorkflow(definitionId, body);
}
@Get('/instance')
getWorkflowInstances(
@Query('definitionId') definitionId,
😞 Promise<WorkflowInstance[]> {
return this.workflowService.getWorkflowInstances(definitionId);
}
@Get('/instance/:workflowInstanceID')
getWorkflowInstance(
@Param('workflowInstanceID') workflowInstanceID,
😞 Promise<WorkflowInstance> {
return this.workflowService.getWorkflowInstance(workflowInstanceID);
}
@Get('/instance/:workflowInstanceID/context')
getWorkflowContext(
@Param('workflowInstanceID') workflowInstanceID,
😞 Promise<any> {
return this.workflowService.getWorkflowContext(workflowInstanceID);
}
@Get('/instance/:workflowInstanceID/usertask')
getUserTasks(
@Param('workflowInstanceID') workflowInstanceID,
😞 Promise<TaskInstance> {
return this.workflowService.getUserTasks(workflowInstanceID);
}
@Patch('/usertask/:taskInstanceID')
@HttpCode(204)
updateUserTask(
@Body() body,
@Param('taskInstanceID') taskInstanceID,
😞 Promise<void> {
return this.workflowService.updateUserTask(taskInstanceID, body);
}
}
cf create-service destination lite wf_cloud_sdk-destinationxs-security.json file with the following content.{
"xsappname": "wf_cloud_sdk",
"tenant-mode": "dedicated"
}cf create-service xsuaa application wf_cloud_sdk-xsuaa -c xs-security.jsonmanifest.yml.applications:
- name: wf_cloud_sdk
path: deployment/
buildpacks:
- nodejs_buildpack
memory: 256M
command: npm run start:prod
random-route: true
services:
- wf_cloud_sdk-destination
- wf_cloud_sdk-xsuaa
npm run deploy"onboard", but any workflow definition can be used.?definitionId=onboard, up to 10 workflow instances will be retrieved in descending order by creation date./workflow/instance?definitionId=onboard
/workflow/instance/<INSTANCE_ID>
/workflow/instance/<INSTANCE_ID>/context
/workflow/instance/onboard{
"managerId": "john.edrich@sapdemo.com",
"buddyId": "kevin.hart@saptest.com",
"userId": "cgrant1",
"empData": {
"firstName": "Carla",
"lastName": "Grant",
"city": "San Mateo",
"country": "United States",
"hireDate": "2020-07-11",
"jobTitle": "General Manager, Industries"
}
}
/workflow/instance/<INSTANCE_ID>/usertask
/workflow/usertask/<USER_TASK_ID>{
"approve": true
}
/workflow/instance/<INSTANCE_ID>/usertask
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 6 | |
| 5 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 |