RE: Error when send email in suite script 2.0

Hi All , I got  this error (email.send is not a function) when i apply this client script:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define([‘N/runtime’,  ‘N/email’], function(runtime, email) {
            function pageInit(context) {
                if (context.mode === ‘edit’) {
                    var message = “you dont have phonenumber!”;
                    var phone = context.currentRecord.getValue({
                        fieldId: ‘phone’
                    });
                    if (!phone) {
                        alert(message);
                    }
                }
            }
            function fieldChanged(context) {
                var record = context.currentRecord;
                 var myUser = runtime.getCurrentUser().name;
                try {
                    var myrec = record.getValue({
                        fieldId: ‘custbody_sor_ordercategory’
                    });
                    if (myrec == 1) {
                        record.setValue({
                            fieldId: ‘custbody_sor_temptest’,
                            value: myUser
                        });
                    } else {
                        record.setValue({
                            fieldId: ‘custbody_sor_temptest’,
                            value: null
                        });
                    }
                } catch (e) {
                    console.log(‘ERROR’, JSON.stringify(e));
                }
            }
            function sendemail() {
                var userid = runtime.getCurrentUser().user;
                var useremail = runtime.getCurrentUser().email;
                email.send({
                        author: userid,
                        recipients: useremail,
                        subject: ‘Test’,
                        body: ‘my first email’,
                       attachments: null,
                        relatedRecords: null
                        });
                    }
                    return {
                        pageInit: pageInit,
                        fieldChanged: fieldChanged,
                        saveRecord: sendemail
                    };
                });
butterflyeffect Rookie Asked on January 18, 2021 in SuiteScript.
Add Comment
2 Answers

There’s nothing obviously wrong. When do you get the error?

Intermediate Answered on January 22, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.