-2

In netsuite, I write the these code but I face a problem as

ReferenceError nlapiCreateFile is not defined

Code:

function creatingFile() {
    var file = "xxxxx";
    var fileObj = nlapiCreateFile('mycsv.csv','CSV',file); // Error !!!
    nlapiSendEmail(15,'epost@xx.com,"subject" ,fileObj, null, null, null, null);
}
  • In which script type is this function running? If it's client script, this will explain the error. The nlapiCreateFile api is not supported on client scripts. – Igor Po Dec 01 '17 at 16:07

2 Answers2

0

I have some similar old 1.0 code that works just fine. From a quick glance that is probably failing due to the "file" variable not being defined, and you have an extra apostrophe in the nlapiSendEmail function. Is that defined as a global variable earlier on in your script, also is "x" defined as an email address or internal ID?

Try running it with some try catch statements to get more specific error information. This should give you enough information for debugging where your problem is at.

function creatingFile(){
  var fileContents='ASDFASDf,asdfgasfasdf';
  var folderID='12345'; //replace with a valid folder internal ID.
  try{
    var fileObj=nlapiCreateFile('mycsv.csv','CSV',fileContents);
    fileObj.setFolder(folderID);
    var fID=nlapiSubmitFile(fileObj);
  }catch(err01){
    nlapiLogExecution('DEBUG','ERROR 01',JSON.stringify(err01));
  }

  try{
    nlapiSendEmail(15,x,"asd",fID,null,null,null,null);
  }catch(err02){
    nlapiLogExecution('DEBUG','ERROR 02',JSON.stringify(err02));
  }
}
w3bguy
  • 2,215
  • 1
  • 19
  • 34
  • 1
    u are right about nlapiSendEmail function i fix it but my problem is about [code] var file = "asdsadsa"; var fileObj = nlapiCreateFile('mycsv.csv','CSV',file); [code] – Nazım Utku ATLI Dec 01 '17 at 13:49
  • I took another look at my code. Looks like you are missing the folder as well. I'll update my answer to show you. – w3bguy Dec 01 '17 at 17:23
0

I believe you are running into what I would consider a "bug", but NetSuite may disagree. If you are calling your creatingFile() function from a user event (i.e. a button on the Suitelet form, etc), that seems to fall under the category of "client script" in NetSuite logic, and the nlapiCreateFile function is not available in Client script context. This is not at all intuitive because, from my perspective, it's all part of the Suitelet, which is supported for that function. The only way I found to work around it is to create the file on load of the script, not on action of the user. However, this has resulted in other issues I haven't figured out yet, such as how I use the newly created file object in the client context once the customer clicks the button (I'm trying to send the file as an email attachment).

Mageician
  • 2,918
  • 9
  • 43
  • 69