How to get custom field values using n/currentReco...
# ask-stanley-ai
a
How to get custom field values using n/currentRecord module when record is in VIEW mode. Client script is executing on button click where the button was added through a UE script
c
AI generated answer (using internal Slack threads):
In NetSuite, when you are in VIEW mode, the
N/currentRecord
module does not contain all the field values. It only contains the
recordtype
and
id
. This is why you are getting
undefined
when trying to access custom field values using
N/currentRecord.get().getValue()
or
N/currentRecord.get().getText()
. However, you can use the
recordtype
and
id
to load the record using
N/record.load()
or
N/search.lookupFields()
to retrieve the custom field values. Here is an example of how you can do this:
Copy code
javascript
define(['N/record', 'N/currentRecord'], function(record, currentRecord) {
    function handleButtonClick() {
        var rec = currentRecord.get();
        var recordType = rec.type;
        var recordId = rec.id;

        // Load the record
        var loadedRecord = record.load({
            type: recordType,
            id: recordId
        });

        // Get the custom field value
        var customFieldValue = loadedRecord.getValue({ fieldId: 'customfield' });
    }

    return {
        handleButtonClick: handleButtonClick
    };
});
In this example,
handleButtonClick
is the function that is executed when the button is clicked. It first gets the current record and its type and id. Then it loads the record using
N/record.load()
. Finally, it retrieves the custom field value using
getValue()
. Remember, this approach will work only if the record is not in edit mode, as
N/currentRecord
does not work in edit mode. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.864851952
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858074427
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.849384665
Please provide your feedback on this answer.