> 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="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FkrkKRn1zSvwMg32r76Dt%2Fimage.png?alt=media&amp;token=39b139de-8d51-4419-9905-718af160f794" 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="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2F8W8yF1oCRY2uEPsPyBOI%2Fimage.png?alt=media&amp;token=2fdc7ff3-a49b-463b-8ff6-e09f5bb1b342" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FWV2z1PuOufkJxTU3a1Rp%2Fimage.png?alt=media&amp;token=f08efa0f-2e00-45f2-8f3e-0ab2cd36ff07" 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="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FH8B4yNlCxS6EDyxOdKNE%2Fimage.png?alt=media&amp;token=0f0df99d-b63b-4b18-8017-c542ba2fb7a8" alt=""><figcaption></figcaption></figure>

resulting in:

<figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2F5HhxyCLKg3BxTfG78D9W%2Fimage.png?alt=media&amp;token=f70d612a-ca9d-43ec-bc05-12dd3e338d0e" alt=""><figcaption></figcaption></figure>
