> For the complete documentation index, see [llms.txt](https://docs.keyfax.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keyfax.biz/product-suite/keynamics/configuration/mappings/mapping-lookup-fields.md).

# Mapping Lookup fields

Keyfax scripts can return data that is used to make a selection in **Lookup** fields in your Dynamics forms. It is important to ensure that the data supplied by the Keyfax script ***exactly*** matches the item as it appears in Dynamics, e.g. if you want this to become the current selection:\
&#x20;  &#x20;

<figure><img src="http://help.keyfax.biz/KeyNamics/images/1592473181646.png" alt=""><figcaption></figcaption></figure>

your script will need to return the exact value '**Anti-Social Behaviour**'.\
\
**Lookup** field selections can only be made via **FetchXml** queries. This is necessary in order to find the **internal Id** of the selection. Considering the example above, this involves **two Mapping entries and a FetchXml query**:

1. The first will read the **CaseType** value from the data exported by the Keyfax script. This Mapping will either pick up the data pointed at by the xPath statement in the **Source**, or, if this isn't found, the default text '**General Enquiry**' will be used. The value returned is not going to be stored *directly* into a Dynamics Form field, rather, it is going to be used as a **Bookmark** inside a **FetchXml** query that will pick up the required unique **Id**. For this reason, the target is set to '**null**', e.g:

<figure><img src="/files/leBNvLRYfsn9hRmHNSum" alt=""><figcaption></figcaption></figure>

2. Create the **FetchXml** query that will retrieve the **Id** of the Lookup entry that we wish to select (i.e. **cust\_casetypeid**). This uses the value supplied by the **Bookmark** above, so at run time the **condition** statement actually reads as:

<figure><img src="/files/fp8GRJbjhD3KoTr6oUsb" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/fziWOfirwM4O20E0V2aU" alt=""><figcaption></figcaption></figure>

3. Finally, the **Mapping** entry itself which executes the **FetchXml** statement above and the **cust\_casetype** Target will now reflect the expected selection:

<br>

<figure><img src="/files/dl5Yx8skstMT5UrSAiw5" alt=""><figcaption></figcaption></figure>

resulting in:

<figure><img src="/files/3YnOUOtmdohjJJkN6Mna" alt=""><figcaption></figcaption></figure>
