Hello all.. First off I am a n00b trying to learn ...
# suitescript
t
Hello all.. First off I am a n00b trying to learn SuiteScript. Currently I'm trying to disable the default shipping, billing checkboxes on the address pop up (in the customer center) - my example is showing what works, and ive commented out the default shipping which does not The error I get when I try to set default shipping is: Uncaught TypeError: Cannot read properties of null (setting 'isDisabled') If i try to disable a custom body field (on the sales order record, not the ship to window) it works.. Im sure im missing something quite important lol 🙂 any insight is appreciated..
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 */

define (['N/record'], (record) => {

var exports = {};

 function pageInit(context) {

     const myRecord = context.currentRecord;
       const myRecordFieldA = myRecord.getField({
         fieldId: 'custbody_use_customer_label'
        });
  
    /* const myRecordFieldB = myRecord.getField({
         fieldId: 'defaultshipping'
        });*/

        myRecordFieldA.isDisabled = true;
    //  myRecordFieldB.isDisabled = true;
 }


exports.pageInit = pageInit;
return exports;
});
Forgot to note that im running this on the custom code of the custom customer center form.
s
I believe the fields are related to the form, not the currentRecord. You should try with
context.form
instead
t
I can use context.form on a client script?
r
One more tip, you can always try to use console.log to see if you are getting the desired values or not. Like in your case. When you tried getting the field in myRecordFieldA you can print the variable using console.log and see if you are getting field.
s
I was mistaken
context.currentRecord.getField(fieldId)
should be the correct syntax
✅ 1
t
@raghav - this is what i get console log results: My customer label currentRecordField My default shipping null It is like, its trying to check before the whole form has loaded, so it thinks it does not exist or is null (which in this case yes it will be either "checked/unchecked")
Then after the console log checks the value, I get this: Uncaught TypeError: Cannot set properties of null (setting 'isDisabled')
b
how did you deploy the client script
n
I know it shows in the UI but is "defaultshipping" even a field? Curiously it doesn't show in the records browser. I suspect you need DOM manipulation.
r
I wanted to highlight printing the first variable. Because many developer don't check what they are getting in a first variable and keep on writing the code hoping everything will be fine. To further clarify, In your case you were not able to get the field itself. You can't disable something which you don't have. Pageinit triggers after the page is loaded so don't worry about that. And last point is defaultshipping is not a field that stores data. It populates the data when the page is loaded. Don't remember the exact word which we use to describe such field. I am not sure about if we can disable or take any action on such fields. But assuming you are using a client script you should be able to.
💯 1
n
I have found validateField code so you can access it at some point but as mentioned above, it's not around at pageInit maybe try postSourcing...
b
how the script is deployed matters for an address
in particular, you would not be able to access transaction fields and address fields using the same script unless you have 2 client scripts sharing the same code
r
This is interesting. Would you mind elaborating it a bit more @battk. I will check it out soon myself as well.
n
You mean applying it via the form through "custom code"?
b
the address is a subrecord
its fields are not available to a client script deployed to the parent transaction
the guess here is that the client script is deployed to the sales order, which explains why
custbody_use_customer_label
exists and
defaultshipping
does not
Customizing Address Forms details how to deploy to address forms, basically what @NElliott says
Client Scripts Attached to the Address Subrecord details unusual things about scripts deployed to addresses
n
@battk Good spot on custbody_ I read past it thinking it was a custom field on the address record 😉