# Update UDF/Custom Field Information with Batch Operations

As previously shown in [Update UDF/Custom Field Values for a Derived Sample Output](/api-and-database/api-docs/cookbook/work-with-process-step-outputs/update-udf-custom-field-values-for-a-derived-sample-output.md), 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="/files/boSBuHKOda3ucU5UvK1c" 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="/files/hfyu73r9xvi9D3hLLq6n" alt=""><figcaption></figcaption></figure>

### Attachments

UsingBatchPut.groovy:

{% file src="/files/XndLrkgoWureHWpQ5yEW" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.claritylims.illumina.com/api-and-database/api-docs/cookbook/work-with-batch-resources/update-udf-custom-field-information-with-batch-operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
