Kuali GraphQL Documentation

Guides

Start a workflow

Use code to start a workflow and submit a form.


Overview

Starting a workflow involves three steps.

  1. Initialize the workflow
  2. Get the draft document id
  3. Submit the document with data to the workflow

To simplify things, the example below uses a very simple form with only one field. A typical form will have much more data involved, but the process will still be these three steps, just with more data in the submit document step.

Step 1: Initialize the workflow

Call the initializeWorkflow mutation to start the workflow and get the actionId for the workflow you started.

Query

      
        mutation ($appId: ID!) {
  initializeWorkflow(args: {id: $appId}) {
    actionId
  }
}

      
    

Variables

      
{
  "appId": "63e2d5339ed71b32ade73a42"
}

      
    

Results

      
        {
          "data": {
            "initializeWorkflow": {
              "actionId": "6402959d200606e80fe6f20d"
            }
          }
        }
      
    

Step 2: Get the draft document id

When the workflow is initiated it creates an empty draft of a document. We need the id of that document in order to give it data and submit it to the workflow. Note: We pass the actionId from the initializeWorkflow operation as a variable here.

Query

      
        query ($actionId: String!) {
  action(actionId: $actionId) {
    id
    appId
    document {
      id
    }
  }
}

      
    

Variables

      
{
  "actionId": "6402959d200606e80fe6f20d"
}

      
    

Results

      
        {
          "data": {
            "action": {
              "id": "6402959d200606e80fe6f20d",
              "appId": "63e2d5339ed71b32ade73a42",
              "document": {
                "id": "64029dab6f0562f58f91a206"
              }
            }
          }
        }
      
    

Step 3: Submit the document

Now we submit the document with the data and the workflow moves to the first step and is fully started. Note that we pass the status as completed to tell the workflow that the first step of submitting the document is complete.

Query

      
        mutation ($documentId: ID!, $data: JSON, $actionId: ID!, $status: String) {
  submitDocument(
    id: $documentId
    data: $data
    actionId: $actionId
    status: $status
  )
}

      
    

Variables

      
{
  "documentId": "64029dab6f0562f58f91a206",
  "data": {
    "dORA8YYBmX": "English 450"
  },
  "actionId": "6402959d200606e80fe6f20d",
  "status": "completed"
}

      
    

Results

      
        {
          "data": {
            "submitDocument": "Ok"
          }
        }