This content has been archived.

Table of Contents

Listing case types and creating cases with the Connect SDK on iOS

This tutorial demonstrates how to configure and integrate the Connect SDK features with a new iOS application that was created in the Xcode development environment by using the Swift language. The tutorial explains how to use the Connect SDK Casetypes API to obtain a list of case types and create a case.

The tutorial contains the following sections:

This walkthrough takes approximately 25 minutes to complete.

Prerequisites

Before you start this tutorial, do the following tasks:

  • Read Tutorial: Creating a Hello World iOS app with the Connect SDK, which demonstrates how to set up the Connect SDK in the Xcode environment, initialize it in the application, and use it to authenticate.
  • Download the ZIP file, which contains the sample Swift code and other Xcode project files for the iOS app described in this tutorial.

You can connect to any Pega® Platform instance to test the sample iOS app. Make sure that it already includes some cases and assignments.

Obtaining case types

You can use the Casetypes API to obtain a list of case types for the authenticated user.

  1. In the Xcode environment, click New > File > Cocoa Touch Class and create a subclass of UITableViewController.
  2. Name the subclass CaseTypesVC.This subclass is where all the logic that is related to obtaining case types is placed. It is linked to a separate scene of your application's user interface. This scene should be based on a template or be inherited from the class.
  3. Declare a caseTypes property to represent the obtained case types for this new class:
    var caseTypes = [PMCaseType]()
  4. Create the getCaseTypes() method for the CasesTypesVC class. Make a call to the getAll() method of the casetypesService Connect SDK object to obtain a list of available case types. When successful, this method returns a list of available case types in the casesTypes completion block parameter. The returned array is then referenced by the local casesTypes property for the CaseTypesVC class:
    func getCaseTypes() {
        PegaApi.shared.casetypesService.getAll { caseTypes, error in
            if let error = error {
                self.showAlert(with: error)
            } else if let caseTypes = caseTypes {
                self.caseTypes = caseTypes
                DispatchQueue.main.async {
                    self.tableView.reloadData()
                }
            }
        }
    ​}
    
  5. Override the viewWillAppear() method for the class and call the getCaseTypes() method so that the getCaseTypes() method is called when the CaseTypesVC view is about to appear. Override important methods inherited from UITableViewController: tableView(_:numberOfRowsInSection:), tableView(_:cellForRowAt:), tableView(_:didSelectRowAt:), prepare(for segue:sender:) so that the fetched case types are presented in the CaseTypesVC table view cells. For a preview of the implementation, see the demo project.

    Case types list - CaseTypes API

    Case types list - CaseTypes API

     

Creating a case

The code developed in this section demonstrates how to create a case in your iOS application by using the Casetypes API of the Connect SDK.

  1. Click New > File > Cocoa Touch Class in the Xcode environment and create a subclass of UIViewController.
  2. Name the subclass CreateCaseVC. This subclass is where all the logic for creating a case is placed. It is linked to a separate scene of your application's user interface. This scene should be based on a template or be inherited from another class.
  3. Define the caseTypeID property. This is where the current case type is passed from the segue from the CaseTypesVC class:
    var caseTypeID: String?
  4. Create an action connection between the Create case button in the CreateCaseVC scene of the application and the created createCase() method. You can make a call to the createCase() method of the casesService Connect SDK object to create a case in your application.
    @IBAction func createCase() {
        var content = [AnyHashable: Any]()
        if let key = keyTF.text, !key.isEmpty, let value = valueTF.text {
            content[key] = value
        }
        guard let caseTypeID = caseTypeID else {
            return
        }
    ​
        PegaApi.shared.casesService.createCase(caseTypeID: caseTypeID, processID: "pyStartCase", parentCaseID: nil, content: content) { caseRef, error in
            DispatchQueue.main.async {
                if let error = error {
                    self.showAlert(with: error)
                    self.resultTF.text = "Error occurred!"
                } else {
                    self.resultTF.text = "Case created successfully!"
                }
            }
        }
    ​}

    Create case - CaseTypes API

    Create case - Case API

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.