# Update UDF/Custom Field Information with Batch Operations

As previously shown in [update-udf-custom-field-values-for-a-derived-sample-output](https://help.claritylims.illumina.com/api-and-database/api-docs/cookbook/work-with-process-step-outputs/update-udf-custom-field-values-for-a-derived-sample-output "mention"), you can update the user-defined fields/custom fields of the derived samples (referred to as analytes in the API) generated by a step. This example uses batch operations to improve the performance of that script.

As of Clarity LIMS v5, the term **user-defined field** (UDF) has been replaced with custom field in the user interface. However, the API resource is still called **UDF**.

* **Master step fields**—Configured on master steps. Master step fields only apply to the following:
  * The master step on which the fields are configured.
  * The steps derived from those master steps.
* **Global fields**—Configured on entities (eg, submitted sample, derived sample, measurement, etc.). Global fields apply to the entire Clarity LIMS system.

### Prerequisites

Before you follow the example, make sure that you have the following items:

* A global custom field named Library Size that on the Derived Sample object.
* A configured Library Prep step that applies Library Size to generated derived samples.
* A Library Prep step that has been run and has generated derived samples.
* A compatible version of API (v2 r21 or later).

### Code Example <a href="#example" id="example"></a>

In Clarity LIMS, the **Record Details** screen displays the information about the derived samples generated by a step. You can view the global fields associated with the derived samples in the Sample table.

The screenshot below shows the **Library Size** values for the derived samples.

<figure><img src="https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-b73f9f7432a83fb6a3e4279742662aafdb2f8125%2FUpdatingSampleInfoLibrarySizeSampleDetails_swCL.jpeg?alt=media" alt=""><figcaption></figcaption></figure>

Derived sample information is stored in the API in the **analyte** resource. Step information is stored in the **process** resource. Each global field value is stored as a **udf**.

An **analyte** resource contains specific derived sample details that are recorded in lab steps. Those details are typically stored in **global fields**, configured in the LIMS on the **Derived Sample** object and then associated with the step. When you update the information for a derived sample by updating the **analyte** API resource, only the global fields that are associated with the step can be updated.

#### Step 1. Retrieve the Process Information <a href="#step1" id="step1"></a>

To retrieve the process information, you can perform a GET on the created process URI, as follows:

```
processURI = "http://${hostname}/api/v2/processes/${processLIMSID}"
process = GLSRestApiUtils.httpGET(processURI, username, password)
```

#### Step 2. Retrieve URIs of Output Analytes <a href="#step2" id="step2"></a>

You can now collect all of the output analytes and harvest their URIs:

#### Step 3. Retrieve Analytes <a href="#step3" id="step3"></a>

After you have collected the output analyte URIs, you can retrieve the analytes with a batchGET() operation. The URIs must be unique for the batch operations to succeed.

```
def outputNodes = GLSRestApiUtils.batchGET(outputAnalyteURIs, username, password)
```

#### Step 4. Set Analyte **Library Size** UDF <a href="#step4" id="step4"></a>

You can now iterate through our retrieved list of analytes and set each analytes **'Library Size**' UDF to 25.

```
outputNodes.each {
    GLSRestApiUtils.setUdfValue(it, 'Library Size', '25')
}
```

#### Step 5. Update Analytes <a href="#step5" id="step5"></a>

To update the analytes in the system, call **batchPUT()**. It will attempt to call a PUT for each node in the list. (Note that each node must be unique.)

```
GLSRestApiUtils.batchPUT(outputNodes, username, password)
```

### Expected Output and Results <a href="#results" id="results"></a>

In the **Record Details** screen, the Sample table now shows the updated **Library Size**.

<figure><img src="https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-76b146360a5560ba41b6ed78b9e0fe4fed21f270%2FUpdatingSampleInfoLibrarySizeSampleDetailsUpdated_swCL.jpeg?alt=media" alt=""><figcaption></figcaption></figure>

### Attachments

UsingBatchPut.groovy:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-cc495653475cc9cf5a4d35cee4ddff759e9361f3%2FUsingBatchPut.groovy?alt=media&token=535f8727-5109-4588-9a2b-e3c89f664355>" %}
