Hello, all. I'm writing a simple Client script fun...
# suitescript
a
Hello, all. I'm writing a simple Client script function to handle a button click (button injected by beforeLoad UE) on a Sales Order record. The button is firing the client function correctly. My problem is that with this custom function I don't have access to the context object (or, at least, I don't know how to get access to it) and so am trying to use N/currentRecord.get() to get the record and read the entity / Customer ID. Unfortunately, no matter how I try to read that value with currentRecord.get().getValue() or .getText(), I get nothing but undefined. Confusingly, if I read the shipdate field using currentRecord.get().getValue(), I get the value just fine. Can anyone explain why using this method to read the entity field would turn up with undefined?
Copy code
define([
    'N/currentRecord',

], function (
    currentRecord,
) {
    var exports = {};

    function pageInit(context) {
        console.log("pageInit Triggered!");
    }
    exports.pageInit = pageInit;

    function handleGenerateDelivPacketButtonClick() {
        debugger;

        let rec = currentRecord.get();

        // All of the following function calls return undefined
        let recCustomerId = rec.getValue('entity');
        let recCustomerId2 = rec.getText('entity');
        let recCustomerId3 = rec.getValue({ fieldId: 'entity' });
        let recCustomerId4 = rec.getText({ fieldId: 'entity' });

        // This returns the ship date accurately (e.g. '6/28/2023')
        let recShipDate = rec.getValue('shipdate');

    }
    exports.handleGenerateDelivPacketButtonClick = handleGenerateDelivPacketButtonClick;
}
e
If you're adding and clicking the button from
VIEW
mode, then the
CurrentRecord
instance will not contain any field values, only its
recordtype
and
id
. You can use those values to use
N/record.load()
or
N/search.lookupFields()
to retrieve the
entity
.
a
Thanks, Eric. That makes enough sense to follow as a rule. However, I'm confused about why I can access the Ship Date field value at the same time that the Entity value remains inaccessible. Any thoughts?
Difference between simple text/date field and a record link, perhaps?
e
Ah that is strange
n
You could test it with a
currentRecord.get().getText({fieldId: 'somefield'})
And see if that gives you the text value. Maybe its just the internal id value of the list/record field that isnt exposed
oh sorry looks like you did already try that. My bad
a
Yeah, I even tried to get at something/anything through getField(), but that didn't lead anywhere
In the end I decided to get the parameters at the UE level and pass them to the Client script via the button definition, but I just find it bizarre that the currentRecord.currentRecord object is apparently so unpredictable/inconsistent
n
That is super frustrating. I mean there really shouldnt be any difference between getting your date field and any other field on the record
a
Ah, Netsuite..
n
netsuite