Coldstar
Coldstar

Reputation: 1341

Cannot create a Restlet dynamically with ss2.0

Why do I get a "Record cannot be created or deleted" error message when trying to create a script record of type record.Type.RESTLET. Has anyone encountered this before or know a workaround? The file gets created fine btw so not sure if there a limitations on creating scripts dymamically

// create the script file and use the id in the restlet script creation below
const script = this.modules.file.create({
    name: `MyRestletFile.js`,
    fileType: this.modules.file.Type.JAVASCRIPT,
    contents: "/**\n@NApiVersion 2.x\n@NScriptType Restlet\n@NModuleScope Public\n*/\ndefine([], function () {return {get: function () {return 'Hello World!'}, post: function (context) {return JSON.stringify(context);}}}); ",
    folder: 123456
});
const scriptFileID = script.save();

// create the restlet script dynamically
const restlet = this.modules.record.create({type: this.modules.record.Type.RESTLET, isDynamic: false});
restlet.setValue({fieldId: 'name', value: 'MyCustomRestlet'});
restlet.setValue({fieldId: 'apiversion', value: '2.0'});
restlet.setValue({fieldId: 'scriptid', value: 'my_custom_restlet'});
restlet.setValue({fieldId: 'scriptfile', value: scriptFileID});
restlet.setValue({fieldId: 'owner', value: 6789});
const scriptId = restlet.save();

Upvotes: 0

Views: 203

Answers (1)

Avi
Avi

Reputation: 2069

Scripts(like RESTlet, Scuitelet) cannot be created using SuiteScript module yet. But you can use SDF to create them.

Upvotes: 1

Related Questions