> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating a GET method for cases

> Add a GET method and GetCases activity to your Pega Service REST that returns all cases available to the user as a JSON array with details and attachments.

To create a GET method for Cases:

1. Create a new Service REST (click **Records → Integration Resources**, right-click **Service Package**, and then click the **Create** command on the shortcut menu).

2. On the form that opens, specify *Cases* as the name of the service, *customapi* as the name of the package, *v2* as the version of the package, and *cases* as the name of the **URI template** and click **Create and open**.\
   **Note:** After you have created the service, make sure that the URL of the service method is as follows: *https\://Server\_Name/prweb/PRRestService/customapi/v2/cases*.

3. On the **Methods** tab, expand the GET method.

4. Click the **Response** tab and create two response conditions:

<table width="100%"><thead><tr><th><p><strong>Process what</strong></p></th><th><p><strong>Parameter values</strong></p></th><th><p><strong>Header fields</strong></p></th><th><p><strong>Message data</strong></p></th></tr></thead><tbody><tr><td><p>pxIsInternalError</p></td><td><ul><li>Condition: <em>When</em></li><li>When name: <em>pxIsInternalError</em></li><li>Content type: <em>application/json</em></li><li>Status code:<em> Param.StatusCode</em></li></ul></td><td> </td><td> </td></tr><tr><td><p>Success response</p></td><td><ul><li>Condition: <em>Default</em></li><li>Content type: <em>application/json</em></li><li>Status code: <em>Param.StatusCode</em></li></ul></td><td><ul><li>Name: <em>etag</em>; Map from: <em>Clipboard</em>; Map from key: <em>Param.eTag</em></li><li>Name: <em>cache-control</em>; Map from: <em>Constant</em>; Map from key: “<em>no-cache</em>”</li></ul></td><td><ul><li>Description: <em>Response</em></li><li>Map from: <em>Clipboard</em></li><li>Map from key: <em>Param.Response</em></li></ul></td></tr></tbody></table>

After you have configured the method, you need to create a new activity named *GetCases*:

1. On the **Parameters** tab, create three variables:
   * result of type *String*
   * currentCaseId of type *String*
   * tempResult of type *String*
2. On the **Steps** tab, complete the following steps:
   1. Get a list of all the cases available to the current user. To do this, call *Call pzGetCasesByFilter* and select the **Pass current parameter page** option. ***pzGetCasesByFilter*** will write all cases to *myStepPage*.
   2. Create a step with a *Property-Set* method that will return cases from *myStepPage* in a loop. To do this, add a loop, and for this loop select the **For each element in value list** and specify the **myStepPage.cases** property. In the method parameters, set the Param.currentCaseID variable to *myStepCase.cases(\<CURRENT>).ID*.
   3. Create a step that will get the details of the case. To do this, type *Call GetCaseDetails* on the **Method** tab and then type *myStepPage.cases(\<CURRENT>)* in **Step Page**. Set the **caseID** parameter to *Param.currentCaseID*.\
      **Note:** Instructions for creating a GetCaseDetails activity are provided [below](#getcasedetails).
   4. Convert the result obtained in the previous step into a string and write it to the Param.tempResult variable.
   5. To generate a valid JSON string, add a comma to the Param.result parameter (i.e. *Param.result + “,”*). In the **When** field, add the following two conditions:
      * If *@IsParamBlank(tools,"result")* is *true*, Skip Step; if the parameter is *false*, Continue Whens.
      * If *@IsParamBlank(tools,"tempResult")* is *true*, Skip Step; if the parameter is *false*, Continue Whens.
   6. Check if **tempResult** is empty. If it is not empty, add the value from **tempResult** to the main result (i.e. *Param.result + Param.tempResult*).
   7. Create the final response **"\["+Param.result+"]"** and write it to the Param.Response variable.

<a id="getcasedetails" />To create a **GetCaseDetails** activity:

1. On the **Parameters** tab, create three variables:
   * caseID of type *String*
   * fileName of type *String*
   * listFileName of type *String*
2. Open the **Pages & Classes** tab and add a page named *Case* of the *Work-* class.
3. On the **Steps** tab, complete the following steps:
   1. In the **Method** field, type *Obj-Open-By-Handle*. In the **Step page** field, add *Case*. In the **InstanceHandle** parameter, type *Param.caseID*.
   2. Create a new *.atachments* property and populate it with the *Case.pyAttachments* list. To create an **attachment** property, click the target icon on the right, and then click **Create and open** on the **Create Property** form. Next, select **Page List** as the property type and type *Link-Attachment* in the **Page definition** field, .
   3. Populate the page with content values. To the **Method** field, write **Page-Copy**; to the **CopyFrom** field, write **Case**; and to the **CopyInfo** field, write **.content**.
