Javascript SuiteScript在客户端脚本中创建文件
我正在尝试在文件柜中创建一个文件,并在客户端脚本中写入它。检查API引用,我发现所有文件对象都只是服务器端的 这是否意味着您不能在客户端脚本中创建和写入文件?我尝试在客户端脚本中使用该代码,但出现错误:Javascript SuiteScript在客户端脚本中创建文件,javascript,file,netsuite,suitescript,Javascript,File,Netsuite,Suitescript,我正在尝试在文件柜中创建一个文件,并在客户端脚本中写入它。检查API引用,我发现所有文件对象都只是服务器端的 这是否意味着您不能在客户端脚本中创建和写入文件?我尝试在客户端脚本中使用该代码,但出现错误: Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"{stack=[Ljava.lang.Object;@59c89ae9
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"{stack=[Ljava.lang.Object;@59c89ae9, toJSON=org.mozilla.javascript.InterpretedFunction@5a4dd71f, name=MODULE_DOES_NOT_EXIST, toString=org.mozilla.javascript.InterpretedFunction@1818dc3c, id=, message=Module does not exist: N/file.js, TYPE=error.SuiteScriptModuleLoaderError}","message":"","stack":[]}
当我试图将它作为脚本文件保存在NetSuite中时。上述情况是否意味着无法在客户端脚本中加载N/File对象
我可以在客户端脚本中写入文件吗?正如您已经发现的,只能从客户端脚本直接调用服务器模块,但这可以通过Suitelet完成。你需要决定Suitelet是如何工作的。可以找到主体工作的示例,并创建一个客户端脚本-此脚本将包含调用Suitelet并在需要时传递当前记录/会话信息的功能
function pageInit{
//required but can be empty
}
function CallforSuitelet(){
var record = currentRecord.get();
var recId = record.id;
var recType = record.type
var suiteletURL = url.resolveScript({
scriptId:'customscriptcase3783737_suitelet',// script ID of your Suitelet
deploymentId: 'customdeploycase3783737_suitelet_dep',//deployment ID of your Suitelet
params: {
'recId':recId,
'recType':recType
}
});
document.location=suiteletURL;
}
return {
CallforSuitelet : CallforSuitelet,
pageInit : pageInit
}
创建Suitelet-此脚本将创建文件
function onRequest(context) {
var requestparam = context.request.parameters;
var recId = requestparam.recId; //the same name of the fields specified in url.resolveScript parameters from Client Script
var recType = requestparam.recType;
var objRecord = record.load({
type: record.Type.___,//insert record type
id: recId
});
var content = 'Insert Content Here';
var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
xml += "<pdf>\n<body font-size=\"12\">\n<h3>Sample PDF</h3>\n";
xml += "<p></p>";
xml += content;
xml += "</body>\n</pdf>";
context.response.renderPdf({xmlString: xml});
}
return {
onRequest: onRequest
}
函数onRequest(上下文){
var requestparam=context.request.parameters;
var recId=requestparam.recId;//与客户端脚本的url.resolveScript参数中指定的字段的名称相同
var recType=requestparam.recType;
var objRecord=record.load({
类型:record.type.\uuuuuuu;//插入记录类型
id:recId
});
var content='在此处插入内容';
var xml=“\n\n”;
xml+=“\n\n示例PDF\n”;
xml+=“”;
xml+=内容;
xml+=“\n”;
renderPdf({xmlString:xml});
}
返回{
onRequest:onRequest
}