# Lab Logic Toolkit FAQ

## What Java/Groovy methods can I use in a Lab Logic Toolkit (LLTK) Expression?

You can use all methods included in the Java and Groovy base packages.

Commonly used Java classes are:

* String: <http://docs.oracle.com/javase/8/docs/api/java/lang/String.html>
* Math: <https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html>

For information on Groovy closures, see [Groovy Closures](https://groovy-lang.org/closures.html).

## How do I handle attempts to access custom fields that do not exist or do not have a value set?

Use the *hasValue* function to check for nonexistent fields and fields that do not have a value set - including toggle switches in LIMS v5 and later.

See [Non-UDF Custom Field Properties](/clarity-lims/integration-toolkits/lltk/lltk-working-with-the-script/lltk-non-udf-custom-field-properties.md).

## How do I prevent a user from moving to the next screen if certain criteria are not met?

Use the *hasValue* function together with the *fail()* method to check for step UDF / custom field values when the Record Details screen is exited, and prevent the user from advancing to the next screen if they have not entered values for these fields.

See [Failing a Script](/clarity-lims/integration-toolkits/lltk/lltk-working-with-the-script/lltk-failing-a-script.md).

## How do I control the number of decimal places for a custom field?

Use the following expression:

1. Use Groovy syntax to format the following string:

   <pre class="language-markup" data-overflow="wrap"><code class="lang-markup">String.format(::%.0f::, step.::counter::)
   </code></pre>
2. Replace *step.::counter::* with the field you want to apply the formatting to.
3. Replace *%.0f* with the number of decimal places needed. For example, for three decimal places, use *%.3f*.

**Example:**

{% code overflow="wrap" %}

```markup
String.format(::%.2f::, Concentration::).
```

{% endcode %}

## How do I round to the closest integer below a value using Math.floor?

Use the following expression:

{% code overflow="wrap" %}

```markup
-exp 'output.::NTP Uses:: = Math.floor((input.::NTP Volume (uL):: - step.::NTP Dead Volume (uL)::)/ step.::NTP Volume Per Lane (uL)::)'
```

{% endcode %}

## How do I use LLTK with required custom fields?

Custom fields are set as a bulk group in the API. The API checks all required fields.

When LLTK updates a field, all required fields must be set or an error will occur.

**Workaround:**

1. Set the required fields with a value such "Please fill in this value".
2. Use another LLTK expression triggered on step completion to check whether this value has been updated.
   * If the field value has been updated, allow the step to proceed.
   * If the field value has not been updated, log an error and halt progress of the step.


---

# 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.connected.illumina.com/clarity-lims/integration-toolkits/lltk/lltk-lab-logic-toolkit-faq.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.
