---
schema_version: "1"
id: ec498c8eac86d5474a0926a3ba1ba6825bf9c74f15bd0468b6de7bc03144da74
title: orderExtensionUtils Service Component Methods
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/cg_task_admin_orderextension_service_component_methods.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.cg_task_admin_orderextension_service_component_methods.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 4e7ee75ef6a514850410cb477b5117f6310539e0abcc4b294c4206ffb037faf2
description: "To access the retail order data, you can use a few out-of-the-box APIs that are exposed in the orderExtensionUtils service component. Example: Accesses order data when the getorderdata API is invoked from the custom LWC component."
products:
  - Consumer Goods
release: "264"
---
# orderExtensionUtils Service Component Methods

To access the retail order data, you can use a few out-of-the-box APIs that are exposed in the orderExtensionUtils service component. Example: Accesses order data when the getorderdata API is invoked from the custom LWC component.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Available in: Lightning Experience</p>
              <p style="margin-bottom:0;">Available in: <strong>Enterprise</strong> and
                <strong>Unlimited</strong> Editions that have Consumer Goods Cloud enabled
              </p>
            </td>

          </tr>
        </tbody>
      </table>

Here are the methods available in the orderExtensionUtils service component:

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-consumer_goods_retail_admin-264-0-0-production-enus/5bb7d7f5-119d-42d0-8596-95e762837019/images/icon_note.png)

Note The API version for all methods is 59.

    
| Method | Description | Syntax | Import Command | Sample Code |
| --- | --- | --- | --- | --- |
| getOrderData | Returns data from order fields. | getOrderData(recordId) | import { getOrderData } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });  }} |
| updateOrderData | Updates order fields. | updateOrderData(recordId, srcThisRef, fieldApiName, value) | import { getOrderData, updateOrderData } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });  }  // You can invoke this method with the click of a button  updateOrderFieldValue() {    const fieldName = 'cgcloud\_\_Delivery\_Note\_\_c';    const newValue = 'test-note';    updateOrderData(this.recordId, this, fieldName, newValue);  }} |
| getOrderItemData | Returns order items data. | getOrderItemData(recordId) | import { getOrderItemData } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderItemsData = \[\];  connectedCallback() {    getOrderItemData(this.recordId).then((data) => {      this.initialOrderItemsData = data;    });  }} |
| updateOrderItemData | Updates order items data. | updateOrderItemData(recordId, srcThisRef, itemId, fieldApiName, value) | import { getOrderItemData, updateOrderItemData } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderItemsData = \[\];  connectedCallback() {    getOrderItemData(this.recordId).then((data) => {      this.initialOrderItemsData = data;    });  }  updateOrderItemFieldData() {    const orderItemId = this.initialOrderItemsData\[0\].Id;    const fieldName = 'cgcloud\_\_Discount\_\_c';    const value = 9;    updateOrderItemData(this.recordId, this, orderItemId, fieldName, value);  }} |
| setCustomState | Sets up additional data to be stored along with the order data. For example, new record creation in a custom object. The additional data setup that uses the setCustomState method can be sent to the custom APEX class handling save customizations. | setCustomState(recordId, customState) | import { setCustomState } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  connectedCallback() {}  setOrderCustomState() {    setCustomState(this.recordId, {      customProp: 'Test'    });  }} |
| getIsOrderInEditMode | Returns whether the order is in edit mode during the initial page load. You can use this information to show custom LWC components only in read-only mode during the initial page load. | getIsOrderInEditMode() | import { getIsOrderInEditMode } from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  @track isOrderInEditMode = false;  connectedCallback() {    this.isOrderInEditMode = getIsOrderInEditMode();  }} |
| registerListenerForOrderDataUpdates | Registers a callback method invoked when any order field changes. | registerListenerForOrderDataUpdates(recordId, thisRef, callback) | import {  getOrderData,  registerListenerForOrderDataUpdates} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  orderDataUpdates = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });    registerListenerForOrderDataUpdates(      this.recordId,      this,      this.handleOrderDataUpdates    );  }  handleOrderDataUpdates(fieldApiName, value) {    this.orderDataUpdates\[fieldApiName\] = value;  }} |
| registerOrderDataInlineValidator | Registers a callback method invoked when an order field changes and performs a validation on the order field. | registerOrderDataInlineValidator(recordId, thisRef, callback) | import {  getOrderData,  registerOrderDataInlineValidator} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });    registerOrderDataInlineValidator(      this.recordId,      this,      this.validateOrderDataChanges    );  }  validateOrderDataChanges(fieldName, value) {    switch (fieldName) {      case 'cgcloud\_\_Invoice\_Note\_\_c':      case 'cgcloud\_\_Delivery\_Note\_\_c':        return this.validateNoteFields(value);      default:        return '';    }  }  validateNoteFields(value) {    if (value && value.length > 100) {      return 'This text should be less than 100 characters';    }  }} |
| registerListenerForOrderItemDataUpdates | Registers a callback method invoked when any order item field changes. | registerListenerForOrderItemDataUpdates(recordId, thisRef, callback) | import {  getOrderItemData,  registerListenerForOrderItemDataUpdates} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderItemsData = \[\];  connectedCallback() {    getOrderItemData(this.recordId).then((data) => {      this.initialOrderItemsData = data;    });    registerListenerForOrderItemDataUpdates(      this.recordId,      this,      this.handleOrderItemDataUpdates    );  }  handleOrderItemDataUpdates(itemId, fieldApiName, value) {    const orderItem = this.initialOrderItemsData.find(      (\_orderItem) => \_orderItem.Id === itemId    );    orderItem\[fieldApiName\] = value;  }} |
| registerOrderItemDataInlineValidator | Registers a callback method invoked when an order item field changes and performs a validation on the order item field. | registerOrderItemDataInlineValidator(recordId, thisRef, callback) | import {  getOrderItemData,  registerOrderItemDataInlineValidator} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderItemsData = \[\];  connectedCallback() {    getOrderItemData(this.recordId).then((data) => {      this.initialOrderItemsData = data;    });    registerOrderItemDataInlineValidator(      this.recordId,      this,      this.validateOrderItemDataChanges    );  }  validateOrderItemDataChanges(itemId, fieldName, value) {    switch (fieldName) {      case 'Discount\_\_c':        return this.validateDiscount(value);      default:        return '';    }  }  validateDiscount(value) {    if (value > 10) {      return 'Item discount should not be more than 10%';    }    return '';  }} |
| registerBeforeAddItemActionHandler | Registers a callback method before adding items in an order. | registerBeforeAddItemActionHandler(recordId, thisRef, callback) | import {  getOrderData,  registerListenerForOrderDataUpdates,  registerBeforeAddItemActionHandler} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  orderDataUpdates = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });    registerListenerForOrderDataUpdates(      this.recordId,      this,      this.handleOrderDataUpdates    );    registerBeforeAddItemActionHandler(      this.recordId,      this,      this.handleBeforeAddItemCB    );  }  handleOrderDataUpdates(fieldApiName, value) {    this.orderDataUpdates\[fieldApiName\] = value;  }  handleBeforeAddItemCB(newOrderItems) {    const orderData = { ...this.initialOrderData, ...this.orderDataUpdates };    newOrderItems = newOrderItems.map((orderItem) => {      if (        orderData.cgcloud\_\_Order\_Account\_\_r.Name === '\*NTO Store #201' &&        orderItem\['Product\_\_r.Description\_1\_\_c'\] === 'BBQ'      ) {        throw new Error("You can't add BBQ product");      }      orderItem.Quantity\_\_c = 2;      orderItem.Number\_\_c = 10;      return orderItem;    });  }} |
| registerBeforeSaveActionHandler | Registers a callback method before saving an order. | registerBeforeSaveActionHandler(recordId, thisRef, callback) | import {  getOrderData,  registerBeforeSaveActionHandler} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });    registerBeforeSaveActionHandler(      this.recordId,      this,      this.handleBeforeSaveCB    );  }  handleBeforeSaveCB(savePayload) {    const {      orderItemsToBeUpserted: orderItems,      updatedOrder: orderData    } = savePayload;    for (let i = 0; i < orderItems.length; i++) {      const orderItem = orderItems\[i\];      if (orderItem.cgcloud\_\_Quantity\_\_c > 90) {        throw new Error("Order Item Quantity shouldn't be more than 90");      }    }    let headerDiscount = orderData.cgcloud\_\_Header\_Discount\_Percentage\_\_c;    headerDiscount = headerDiscount && Number(headerDiscount);    if (headerDiscount && headerDiscount > 15) {      throw new Error("Header discount can't be greater than 15");    }    let deliveryDate = orderData.cgcloud\_\_Delivery\_Date\_\_c;    if (deliveryDate) {      deliveryDate = new Date(deliveryDate);      deliveryDate.setDate(deliveryDate.getDate() + 1);      orderData.cgcloud\_\_Delivery\_Date\_\_c = deliveryDate;    }  }} |
| registerListenerForEnablingOrDisablingEditMode | Returns whether the order is in edit mode during the order taking process. You can use this information to show custom LWC components only in read-only mode. | registerListenerForEnablingOrDisablingEditMode(recordId, thisRef, callback) | import {  getOrderData,  registerListenerForEnablingOrDisablingEditMode} from 'cgcloud/orderExtensionUtils'; | {  @api recordId;  initialOrderData = {};  connectedCallback() {    getOrderData(this.recordId).then((data) => {      this.initialOrderData = data;    });    registerBeforeSaveActionHandler(      this.recordId,      this,      this.handleBeforeSaveCB    );  }  handleBeforeSaveCB(savePayload) {    const {      orderItemsToBeUpserted: orderItems,      updatedOrder: orderData    } = savePayload;    for (let i = 0; i < orderItems.length; i++) {      const orderItem = orderItems\[i\];      if (orderItem.cgcloud\_\_Quantity\_\_c > 90) {        throw new Error("Order Item Quantity shouldn't be more than 90");      }    }    let headerDiscount = orderData.cgcloud\_\_Header\_Discount\_Percentage\_\_c;    headerDiscount = headerDiscount && Number(headerDiscount);    if (headerDiscount && headerDiscount > 15) {      throw new Error("Header discount can't be greater than 15");    }    let deliveryDate = orderData.cgcloud\_\_Delivery\_Date\_\_c;    if (deliveryDate) {      deliveryDate = new Date(deliveryDate);      deliveryDate.setDate(deliveryDate.getDate() + 1);      orderData.cgcloud\_\_Delivery\_Date\_\_c = deliveryDate;    }  }} |