You are here

Starting a Workflow

You learn how to start a workflow.
You need to have completed the tutorial Retrieving Process Definitions, as you build on the code created there.
  1. In the project you worked on previously, replace the createWorkflow method. This code sets up a workflow process and then starts it:

              
    - (void) createWorkflow
    {
        NSLog(@"*********** createWorkflow");
        
        // create service
        SkyVaultWorkflowService *workflowService = [[AlfrescoWorkflowService alloc] initWithSession:self.session];
        
        // list process definitions available
        
        [workflowService retrieveProcessDefinitionsWithCompletionBlock:^(NSArray *array, NSError *error) {
            
            if (array == nil)
            {
                NSLog(@"Failed to retrieve process definitions: %@", error);
            }
            
            
            // for each item in the array print out some information
            for (AlfrescoWorkflowProcessDefinition *pd in array)
            {
                NSLog(@"---> Identifier: %@\n", pd.identifier);
                NSLog(@"---> Key: %@\n", pd.key);
                NSLog(@"---> Name: %@\n", pd.name);
                NSLog(@"---> Summary: %@\n", pd.summary);
                NSLog(@"---> Version: %@\n", pd.version);
            }
            
        }];
        
        
        // retrieve process definition for activitiAdhoc:1:4
        
        NSString *processDefinitionID = @"activitiAdhoc:1:4";
        
        [workflowService retrieveProcessDefinitionWithIdentifier:processDefinitionID completionBlock:^(AlfrescoWorkflowProcessDefinition *processDefinition, NSError *error){
            
            if (processDefinition == nil)
            {
                NSLog(@"Failed to retrieve process definition: %@", error);
            }
            else
            {
                
                // start process
                [workflowService startProcessForProcessDefinition:processDefinition assignees:nil variables:nil attachments:nil
                                                  completionBlock:^(AlfrescoWorkflowProcess *process, NSError *error){
                                                      
                                                      NSLog(@"---> Process created!\n");
                                                      NSLog(@"---> identifier: %@\n", process.identifier);
                                                      NSLog(@"---> processDefinitionIdentifier: %@\n", process.processDefinitionIdentifier);
                                                      NSLog(@"---> processDefinitionKey: %@\n", process.processDefinitionKey);
                                                      NSLog(@"---> name: %@\n", process.name);
                                                      NSLog(@"---> startedAt: %@\n", process.startedAt);
                                                      NSLog(@"---> endedAt: %@\n", process.endedAt);
                                                      NSLog(@"---> dueAt: %@\n", process.dueAt);
                                                      NSLog(@"---> priority: %@\n", process.priority);
                                                      NSLog(@"---> summary: %@\n", process.summary);
                                                      NSLog(@"---> initiatorUsername: %@\n", process.initiatorUsername);
                                                      
                                                      
                                                      
                                                      // Get tasks for process
                                                      [workflowService retrieveTasksForProcess:process completionBlock:^(NSArray *array, NSError *error){
                                                          
                                                          for (AlfrescoWorkflowTask *task in array)
                                                          {
                                                              NSLog(@"---> Task information:\n");
                                                              NSLog(@"---> identifier: %@\n", task.identifier);
                                                              NSLog(@"---> processIdentifier: %@\n", task.processIdentifier);
                                                              NSLog(@"---> processDefinitionIdentifier: %@\n", task.processDefinitionIdentifier);
                                                              NSLog(@"---> name: %@\n", task.name);
                                                              NSLog(@"---> type: %@\n", task.type);
                                                              NSLog(@"---> startedAt: %@\n", task.startedAt);
                                                              NSLog(@"---> endedAt: %@\n", task.endedAt);
                                                              NSLog(@"---> dueAt: %@\n", task.dueAt);
                                                              NSLog(@"---> summary: %@\n", task.summary);
                                                              NSLog(@"---> priority: %@\n", task.priority);
                                                              NSLog(@"---> assigneeIdentifier: %@\n", task.assigneeIdentifier);                                                             }
                                                          
                                                      }];
                                            
                }];
            }
        }];
    }
    
            
  2. Build and run your code.
  3. Examine the log messages in the Xcode output window:

                
    2014-04-24 10:04:48.365 HelloRepo[13702:60b] ---> Process created!
    2014-04-24 10:04:48.365 HelloRepo[13702:60b] ---> identifier: 90
    2014-04-24 10:04:48.365 HelloRepo[13702:60b] ---> processDefinitionIdentifier: activitiAdhoc:1:4
    2014-04-24 10:04:48.365 HelloRepo[13702:60b] ---> processDefinitionKey: activitiAdhoc
    2014-04-24 10:04:48.366 HelloRepo[13702:60b] ---> name: (null)
    2014-04-24 10:04:48.366 HelloRepo[13702:60b] ---> startedAt: 2014-04-24 09:04:48 +0000
    2014-04-24 10:04:48.367 HelloRepo[13702:60b] ---> endedAt: (null)
    2014-04-24 10:04:48.367 HelloRepo[13702:60b] ---> dueAt: (null)
    2014-04-24 10:04:48.367 HelloRepo[13702:60b] ---> priority: 2
    2014-04-24 10:04:48.367 HelloRepo[13702:60b] ---> summary: (null)
    2014-04-24 10:04:48.368 HelloRepo[13702:60b] ---> initiatorUsername: admin
    2014-04-24 10:04:48.383 HelloRepo[13702:60b] ---> Task information:
    2014-04-24 10:04:48.384 HelloRepo[13702:60b] ---> identifier: 132
    2014-04-24 10:04:48.384 HelloRepo[13702:60b] ---> processIdentifier: 90
    2014-04-24 10:04:48.384 HelloRepo[13702:60b] ---> processDefinitionIdentifier: activitiAdhoc:1:4
    2014-04-24 10:04:48.385 HelloRepo[13702:60b] ---> name: Adhoc Task
    2014-04-24 10:04:48.385 HelloRepo[13702:60b] ---> type: wf:adhocTask
    2014-04-24 10:04:48.385 HelloRepo[13702:60b] ---> startedAt: 2014-04-24 09:04:48 +0000
    2014-04-24 10:04:48.385 HelloRepo[13702:60b] ---> endedAt: (null)
    2014-04-24 10:04:48.386 HelloRepo[13702:60b] ---> dueAt: (null)
    2014-04-24 10:04:48.386 HelloRepo[13702:60b] ---> summary: Adhoc Task
    2014-04-24 10:04:48.386 HelloRepo[13702:60b] ---> priority: 2
    2014-04-24 10:04:48.386 HelloRepo[13702:60b] ---> assigneeIdentifier: admin           
                
              

    Your results may vary depending on the version of SkyVault you are using.

  4. View the logging output and make a note of the TASK identifier for the process just created.
  5. Log into the SkyVault Share interface.
  6. Click My Tasks from the main menu.
  7. Locate the created process and confirm the task identifier matches that of the process just created.
You have created a workflow process with a single task.