---
title: Update
slug: netsuite/50z6-update
description: Learn how to update a credit memo in NetSuite using code, including changing fields, applying it to an invoice, and adding custom fields and line items. This document provides a step-by-step example with the updated credit memo information.
docTags: 
createdAt: 2023-04-25T05:37:20.000Z
---

The following is an example of updating a Credit Memo where we are changing some of the fields. (See [Credit Memo](docId\:rOGVPWAviJlOdMLuJjwd5) for all available fields).  The NetSuite Credit Memo Id (internalId) is required to update the Credit Memo.

:::hint{type="info"}
Note: You can only update one record at a time
:::

The response returns the complete Credit Memo information, but we have shortened the response in our example for ease of reading.

:::CodeblockTabs
Request

```apex
//  Create a Map to store all the data of a CM
Map<String, Object> nsCM = new Map<String, Object>();
    nsCM.put('internalId', '121563');
    nsCM.put('classification', new Map<String, Object>{'internalId'=>'4'});
    nsCM.put('department', new Map<String, Object>{'internalId'=>'3'});
	nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
    nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
    nsCM.put('discountRate', '-20');
    nsCM.put('entity', new Map<String, Object>{'internalId'=>'362'});
    nsCM.put('memo', 'Order 300');
    nsCM.put('otherRefNum', '4343390');
    nsCM.put('tranDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
    
// apply only to Approved status containing invoices and having same customer as credit memo
    List<Object> creditMemoApplyList = new List<Object>();
    Map<String,Object> apply = new Map<String,Object>();
        apply.put('doc', '131747');
        apply.put('line', '0');
        apply.put('apply',true);
        creditMemoApplyList.add(apply);
    nsCM.put('applyList', new Map<String,Object>{'apply'=>creditMemoApplyList,'replaceAll'=>false});

//  Initializing the CM Custom Fields
    List<Object> cmCustomFieldList = new List<Object>();
    Map<String,Object> cmCustomField = new Map<String,Object>();
        cmCustomField.put('fieldType', 'select');
        cmCustomField.put('scriptId', 'custbody_customlist');
        cmCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'3'});
        cmCustomFieldList.add(cmCustomField);

//  Adding the CM Custom Fields
    nsCM.put('customFieldList', new Map<String,Object>{'customField'=>cmCustomFieldList});

//  Initializing the CM Line Items
    List<Object> lineItemList = new List<Object>();
    Map<String, Object> lineItem = new Map<String, Object>();
        lineItem.put('description', 'A weapon for shooting arrows test');
        lineItem.put('item', new Map<String, Object>{'internalId'=>'2917'});
        lineItem.put('replaceAll', false);   
        lineItem.put('amount', 10);
        lineItem.put('quantity', 2);
        lineItem.put('grossAmt', 220);
        lineItem.put('tax1Amt', 210);
        lineItem.put('revRecEndDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
        lineItem.put('revRecStartDate', DateTime.newInstance(2024, 09, 07).getTime()/1000);

//  Initializing the Line Item custom fields
        List<Object> liCustomFieldList = new List<Object>();
        Map<String, Object> liCustomField = new Map<String, Object>();
            liCustomField.put('fieldType', 'boolean');
            liCustomField.put('scriptId', 'custbody_checkbox');
            liCustomField.put('value', 'false');
            liCustomFieldList.add(liCustomField);

//  Adding the CM Line Item Custom Fields
        lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
        lineItemList.add(lineItem);

//  Adding the Line Items to CM
    Map<String, Object> cmLineitemList = new Map<String, Object>();
        cmLineitemList.put('item',lineItemList);
    nsCM.put('itemList',cmLineitemList);

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
    requestJSONMap.put('CreditMemos', new List<Object>{nsCM});
    String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
    reqObj.put('version', '1.0');
    reqObj.put('action', 'updateCreditMemo');
    reqObj.put('requestJSON', reqJSON);

//  Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```

Response

```json
{
  action=updateCreditMemo,
  timestamp= 1682506549179,
  validRequest=true,
  version=1.0,
  responseJSON={
    "status": "200",
    "errors": [],
    "creditMemos": [
      {
        "tranId": "170",
        "tranDate": 1694055600,
        "total": 200.0,
        "taxTotal": 0.0,
        "subTotal": 220.0,
        "subsidiary": {
          "type": null,
          "name": "Parent Company",
          "internalId": "1",
          "externalId": null
        },
        "status": "Open",
        "shippingCost": null,
        "salesRep": null,
        "salesforceID": "a061e000003UzJyAAK",
        "refundCheck": null,
        "otherRefNum": "4343390",
        "memo": "Order 300",
        "location": {
          "type": null,
          "name": "Hyderabad : Hi-Tech City",
          "internalId": "10",
          "externalId": null
        },
        "lastModifiedDate": 1682506545,
        "job": null,
        "itemList": {
          "replaceAll": null,
          "item": [
            {
              "unitsDisplay": null,
              "taxRate1": "0.0",
              "taxCode": {
                "type": null,
                "name": "VAT_IN:No Tax",
                "internalId": "20",
                "externalId": null
              },
              "tax1Amt": 0.0,
              "shipMethod": null,
              "shipGroup": null,
              "serialNumbers": null,
              "revRecStartDate": null,
              "revRecSchedule": null,
              "revRecEndDate": null,
              "rate": null,
              "quantityRemaining": null,
              "quantityReceived": null,
              "quantityPicked": null,
              "quantityPacked": null,
              "quantityOnHand": null,
              "quantityFulfilled": null,
              "quantityCommitted": null,
              "quantityBilled": null,
              "quantityBackOrdered": null,
              "quantityAvailable": null,
              "quantity": 2.0,
              "price": {
                "type": null,
                "name": null,
                "internalId": "-1",
                "externalId": null
              },
              "poNum": null,
              "percentComplete": null,
              "orderLine": null,
              "onHand": null,
              "location": null,
              "line": 6,
              "jobName": null,
              "itemReceive": null,
              "itemName": null,
              "itemIsFulfilled": null,
              "item": {
                "type": null,
                "name": "Fastrack Watch",
                "internalId": "2917",
                "externalId": null
              },
              "isClosed": null,
              "grossAmt": 220.0,
              "expectedReceiptDate": null,
              "description": "A weapon for shooting arrows test",
              "department": null,
              "customFieldList": {
                "customField": [
                  {
                    "valueLookup": null,
                    "value": "false",
                    "scriptId": "custcol_checkbox",
                    "internalId": "443",
                    "fieldType": null
                  }
                ]
              },
              "createPo": null,
              "costEstimateType": "_lastPurchasePrice",
              "costEstimate": 0.0,
              "classification": null,
              "billingSchedule": null,
              "amount": 220.0
            }
          ]
        },
        "internalId": "121563",
        "handlingCost": 0.0,
        "externalId": null,
        "exchangeRate": 23.0,
        "entity": {
          "type": null,
          "name": "21 Atherton Grocery",
          "internalId": "362",
          "externalId": null
        },
        "discountTotal": -20.0,
        "discountRate": "-20.00",
        "discountItem": {
          "type": null,
          "name": "Partner Discount",
          "internalId": "-6",
          "externalId": null
        },
        "department": {
          "type": null,
          "name": "test",
          "internalId": "3",
          "externalId": null
        },
        "customForm": {
          "type": null,
          "name": "Custom Credit Memo 2",
          "internalId": "114",
          "externalId": null
        },
        "customFieldList": {
          "customField": [
            {
              "valueLookup": null,
              "value": "200",
              "scriptId": "custbody42",
              "internalId": "869",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": " - ",
              "scriptId": "custbody_breadwinner_pc_internal_id",
              "internalId": "588",
              "fieldType": null
            },
            {
              "valueLookup": {
                "type": null,
                "name": "C",
                "internalId": "3",
                "externalId": null
              },
              "value": null,
              "scriptId": "custbody_customlist",
              "internalId": "458",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody_checkbox",
              "internalId": "272",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "2",
              "scriptId": "custbody15",
              "internalId": "182",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody_enableimport",
              "internalId": "691",
              "fieldType": null
            }
          ]
        },
        "currencyRecord": {
          "type": null,
          "name": "US Dollars",
          "internalId": "2",
          "externalId": null
        },
        "currencyName": "US Dollars",
        "createdFrom": null,
        "createdDate": 1682505153,
        "classification": {
          "type": null,
          "name": "PC",
          "internalId": "4",
          "externalId": null
        },
        "applyList": {
        "apply": [
          {
            "type": "Invoice",
            "total": 7027.14,
            "refNum": "INV583",
            "line": "0",
            "due": 7027.14,
            "doc": "131747",
            "currencyValue": "INR",
            "applyDate": 1689231600,
            "apply": true,
            "amount": 7027.14
          }
        ]
      },
        "applied": 7027.14,
        "account": {
        "type": null,
        "name": "Accounts Receivable",
        "internalId": "122",
        "externalId": null
        }
      }
    ]
  }
}
```
:::

