---
schema_version: "1"
id: b2f0bb832fa259d1c805a80725d579d40a16f1fd20cb733885571c4cc250d868
title: Access Custom Fields Using Cart Document
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/industries/cme/guides/use-field-mappers-cart-document.md
canonical_url: https://developer.salesforce.com/docs/industries/cme/guide/use-field-mappers-cart-document.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3662f5c31ff3f4d7ea86ea46d35b82f1c3de05670f7e0f6562d948e60785bb6d
products:
  - Communications, Media, Energy and Utilities APIs (Managed Package)
  - Industries Developer Documentation
---
# Access Custom Fields Using Cart Document

You can access custom fields defined on the Order or OrderItem objects by mapping them to keys in the cart document. These keys represent the internal identifiers for the custom fields and should exclude any namespace prefixes or \_\_c suffixes. Once mapped, the custom field values can be retrieved or updated through the cart document wrapper during order or quote processing.

## Use Field Mappers to Add Custom Fields in the Cart Document

Add custom fields to the cart document using field mapping.
After you create the custom field for Order or OrderItem sObjects, you can map them to a key in cart document. Since the key is the internal representation of the custom field in the cart document, it should not have a namespace or "\_\_c". When value for a custom field will be updated using cart document wrapper, this mapping will be used to get the key in cart document and the corresponding node will be updated with the value. Similarly, this mapping will be used to create response (external representation, containing namespace prefix and "\_\_c") from the internal cart document.

Example sample mapping record:

![Sample Mapping Record](https://developer.salesforce.com/docs/media/custom-field-map.png "Sample Mapping Record")

If a new custom field is created on OrderItem then a mapping record for the field should also be created. To create a new mapping.

1. From Setup, in the Quick Find box, enter Custom Settings, and then select **Custom Settings**.
2. Next to Custom Field Maps, click **Manage**.
3. Click **New** and enter the details for your mapping record.

**note:** For new line items, if a custom field's value isn't set by a custom implementation, its default value is applied at the end of the postCartItems process, after validation and pricing.

## Use StandardAPIFields to Add Custom Fields to Cart Document

When using [Cart Document APIs](https://developer.salesforce.com/docs/industries/cme/guide/use-cart-document-cpq.html) in custom implementations such as pre-hooks and post-hooks or custom pricing steps, customers can access fields on both line items and the header object.

By default, only a predefined set of fields is loaded, and only those field values can be retrieved.
To fetch or set a custom field added by the customer on line items using Cart Document APIs, the admin must create a field set on the corresponding object and include the custom field in that field set.

For example, if a custom field `CartType__c` is added to a header object like Order, and there is a requirement to read its value during cart operations in a custom implementation using Cart Document APIs, the customer must perform these steps.

1. Create a field set:  
   Create a new field set named `StandardAPIFields` on the Order object.
   ![Field Set](https://developer.salesforce.com/docs/media/field_set.png "Field Set")

2. Add the custom field:  
   Add the `CartType__c` field to the `StandardAPIFields` field set.
3. Clear cache and regenerate data:  
   Clear the managed platform cache, then run the `Generate EPC Compile Data` job from the **Vlocity CMT Administration** page.
4. Once the setup is complete, the field value can be accessed in custom implementations as shown below.

```
Map<String, Object> args = new Map<String, Object>{'field' => 'CartType__c'};
Map<String, Object> output = cartDocument.call('getCartField', args);
String cartType = (String) output.get('result');
```

Similarly, if a custom field `LineItemType__c` is added to the OrderItem object, the customer must perform these steps.

1. Create a field set:
   Create a new field set named `StandardAPIFields` on the Order Product object.

2. Add the custom field:
   Add the `LineItemType__c` field to the `StandardAPIFields` field set.

3. Clear cache and regenerate data:
   Clear the managed platform cache, then run the `Generate EPC Compile Data` job from the **Vlocity CMT Administration** page.

4. Once the setup is complete, the field value can be accessed in custom implementations as shown below.

```
Map<String, Object> args = new Map<String, Object>{'field' => 'LineItemType__c'};
Map<String, Object> output = cartDocumentItem.call('getItemField', args);
String cartType = (String) output.get('result');
```

**note:** - Custom fields are not populated on the CpqCartDocumentItem during the postCartsItems (AddToCart) scenario.
- Custom fields are not populated by default. However, if custom logic is implemented to set their values, the fields will be populated and accessible like in other APIs.
