# `getFieldValue(record, field)`

Gets a field’s value from a record. Spanning fields are supported.

The field’s value is returned in its raw data form. In some cases, the raw data form differs from the display value that’s returned by [`getFieldDisplayValue(record, field)`](/docs/platform/lwc/guide/reference-get-field-display-value.md).

## Syntax

```javascript
import { getFieldValue } from "lightning/uiRecordApi";
getFieldValue((record: Record), (record: string));
```

## Parameters

| Parameter Name | Type   | Description                                                                                                                                                                                                                                                                                                           | Required?                                                                         |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `record`       | Object | A [Record](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_responses_record.htm) object from which to retrieve the field value.                                                                                                                                                             | ![Yes](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/checkmark.png) |
| `field`        | String | The API name of the field. The value can be either a string or reference to a field imported from `@salesforce/schema`. You can specify up to three **relationship fields** to reference parent objects and fields using this format: `<SObjectName>.<relationship-1>.<relationship-2>.<relationship-3>.<fieldName>`. | ![Yes](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/checkmark.png) |

## Returns

The field’s value. A record may be returned if a relationship field is used. If the field you are requesting for doesn’t exist, this function returns `undefined`.

## Usage

To get the value of a record’s field, you can use the [getRecord](/docs/platform/lwc/guide/reference-wire-adapters-record.md) wire adapter, which returns the property `record.data.fields.fieldName.value`. However, you can also call `getFieldValue(record, field)` to get the value directly.

The field value is returned in its raw data form, which is useful for calculations and comparisons. Here are a few examples of values in raw data form:

- Currency values are displayed like `350000000`.
- Date values are displayed like `2019-07-13`
- Date/time values are displayed like `2015-06-17T22:17:58.000Z`.

Import the field references that you pass to `getFieldValue(record, field)` from the `@salesforce/schema` scoped package using the `@salesforce/schema/ObjectName.FieldName` syntax. For a custom object, use the `@salesforce/schema/CustomObjectName__c.CustomFieldName__c` syntax. If you use a string to identify a field name like `fields: ["Account.Name"]`, you don't get the benefits that you get from importing a reference to the field. See [Import References to Salesforce Objects and Fields](/docs/platform/lwc/guide/data-wire-service-about.md).

```javascript
import { LightningElement, api, wire } from "lwc";
import { getRecord, getFieldValue } from "lightning/uiRecordApi";

import REVENUE_FIELD from "@salesforce/schema/Account.AnnualRevenue";
import CREATED_FIELD from "@salesforce/schema/Account.CreatedDate";
import EXP_FIELD from "@salesforce/schema/Account.SLAExpirationDate__c";

const FIELDS = [REVENUE_FIELD, CREATED_FIELD, EXP_FIELD];

export default class WireGetValue extends LightningElement {
  @api recordId;

  @wire(getRecord, { recordId: "$recordId", fields: FIELDS })
  account;

  get revenue() {
    return getFieldValue(this.account.data, REVENUE_FIELD);
  }

  get created() {
    return getFieldValue(this.account.data, CREATED_FIELD);
  }

  get expiration() {
    return getFieldValue(this.account.data, EXP_FIELD);
  }
}
```

To display formatted values, use base components such as [`lightning-formatted-number`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-formatted-number) or [`lightning-formatted-date-time`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-formatted-date-time). The locale set in the Salesforce user preferences determines the formatting.

```html
<template>
  <lightning-card title="WireGetFieldValue" icon-name="standard:account">
    <template lwc:if={account.data}>
      <div class="slds-m-around_medium">
        <p>
          <lightning-formatted-number format-style="currency" value={revenue} currency-code="USD">
          </lightning-formatted-number>
        </p>
        <p>
          <lightning-formatted-date-time
            weekday="long"
            month="short"
            year="numeric"
            day="2-digit"
            hour="2-digit"
            minute="2-digit"
            value={created}
          >
          </lightning-formatted-date-time>
        </p>
        <p>
          <lightning-formatted-date-time value={expiration}> </lightning-formatted-date-time>
        </p>
      </div>
    </template>
  </lightning-card>
</template>
```

The base components display the values:

- `$350,000,000.00`
- `Wednesday, Jun 17, 2015, 03:17 PM`
- `Jul 13, 2014`

Alternatively, use the [`getFieldDisplayValue(record, field)`](/docs/platform/lwc/guide/reference-get-field-display-value.md) wire adapter to display the formatted and localized value for a field.

**See Also**

- [Import References to Salesforce Objects and Fields](/docs/platform/lwc/guide/data-wire-service-about.md#import-references-to-salesforce-objects-and-fields)
