-1

i wrote this simple code to send email in suite script 2.0 and i got error " email.send is not a function" /** * @NApiVersion 2.x * @NScriptType ClientScript */ define(['N/runtime', 'N/search', '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
                    };
                });
  • 1
    define(['N/runtime', 'N/search', 'N/email'], function(runtime, search, email) {...} or define(['N/runtime', 'N/email'], function(runtime, email) {...} since you're not using search. – Jala Jan 18 '21 at 17:42

2 Answers2

0

Using development or sandbox accounts may suppress the emails since there is no login context. Try to work on a production account then it should work.

0
define(['N/runtime', 'N/search', 'N/email'], function(runtime, email)

Looks like you've just imported N/search as email, so there is no function email in N/search. Your code must be changed to:

define(['N/runtime', 'N/search', 'N/email'], function(runtime, search, email)