1
votes

I have the below script that I am trying to upload but am getting a Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback - error.

Not sure what I am doing wrong as I am basically following the example in the api.

Note: This is being done in Sandbox.

    /**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/

define(['N/email'],
/**
 * @param {email} email
 */
function(email){
  function sendEmail() {
    var senderId = 34972;
    var recipientEmail = '[email protected]';
    email.send({
      author: senderId,
      recipients: recipientEmail,
      subject: 'Test Sample Email Module',
      body: 'Thisis a test',
    });
  }
  sendEmail();
});
3

3 Answers

2
votes

If you are writing a Suitelet script in 2.0, you need to use the RETURN of your callback function. In your case, it will look something like the following:

return {
    onRequest : sendEmail
};

May I also ask - is there any reason why you are trying to trigger an email send via a SUITELET? Assuming you want to trigger the email via the URL generated on the "script deployment" page of the Suitelet, you should consider including the ServerResponse call to write on your browser that the email was sent successfully. That will look something like the following:

context.response.write('Email now sent');

Lastly - I also see that you have wrongfully used a comma at the end of your 'email.send' object. Remove the comma as pointed out below:

email.send({
  author: senderId,
  recipients: recipientEmail,
  subject: 'Test Sample Email Module',
  body: 'Thisis a test', <---- REMOVE COMMA!
});

Hope this helps.

0
votes

That is not a correct suitelet and you are calling your function inside the define.

The functions returned from the define() may call Netsuite functions but your sendemail function is calling Netsuite APIs “inside” the define.

If you are just trying to wrap your head around SuiteScript change your define to a require and call that code in a console window.

Otherwise review the suitelet docs and return the correct function object.

-2
votes

Here's a straight forward answer... comment out anything that isn't native suite script code... your custom modules, classes and Upload. then edit it in the file cabinet and and un comment your stuff