/** * @NApiVersion 2.1 * @NScriptType Restlet */ define(['N/render', 'N/search', 'N/record'], /** * @param{render} render */ (render, search, record) => { /** * Defines the function that is executed when a GET request is sent to a RESTlet. * @param {Object} requestParams - Parameters from HTTP request URL; parameters passed as an Object (for all supported * content types) * @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an * Object when request Content-Type is 'application/json' or 'application/xml' * @since 2015.2 */ const get = (requestParams) => { try { log.debug({ title: 'get', details: JSON.stringify(requestParams)}); let recId = requestParams.custparam_recid; if (recId) { let lookupObj = search.lookupFields({type: record.Type.INVOICE, id: recId, columns: 'tranid'}); let docNum = lookupObj.tranid; let pdfFile = render.transaction({ entityId: Number(recId), printMode: render.PrintMode.PDF }); let pdfString = pdfFile.getContents(); return { docNum: docNum, pdfString: pdfString } } } catch (ex) { errLog(ex); } } /** * Defines the function that is executed when a PUT request is sent to a RESTlet. * @param {string | Object} requestBody - The HTTP request body; request body are passed as a string when request * Content-Type is 'text/plain' or parsed into an Object when request Content-Type is 'application/json' (in which case * the body must be a valid JSON) * @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an * Object when request Content-Type is 'application/json' or 'application/xml' * @since 2015.2 */ const put = (requestBody) => { } /** * Defines the function that is executed when a POST request is sent to a RESTlet. * @param {string | Object} requestBody - The HTTP request body; request body is passed as a string when request * Content-Type is 'text/plain' or parsed into an Object when request Content-Type is 'application/json' (in which case * the body must be a valid JSON) * @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an * Object when request Content-Type is 'application/json' or 'application/xml' * @since 2015.2 */ const post = (requestBody) => { } /** * Defines the function that is executed when a DELETE request is sent to a RESTlet. * @param {Object} requestParams - Parameters from HTTP request URL; parameters are passed as an Object (for all supported * content types) * @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an * Object when request Content-Type is 'application/json' or 'application/xml' * @since 2015.2 */ const doDelete = (requestParams) => { } const errLog = (e) => { let errObj = e; if (e instanceof String) errObj = JSON.parse(e); let errTyp = 'Native JS'; let errMsg = 'Error: ' + errObj.name + '\n' + 'Message: ' + errObj.message; if (errObj.type === 'error.SuiteScriptError') { errTyp = 'SuiteScript Error'; errMsg += '\n' + 'ID: ' + errObj.id + '\n' + 'Stack Trace: ' + errObj.stack; } else if (errObj.type === 'error.UserEventError') { errTyp = 'User Event Error'; errMsg += '\n' + 'Event Type: ' + errObj.eventType + '\n' + 'Record ID: ' + errObj.recordId + '\n' + 'ID: ' + errObj.id + '\n' + 'Stack Trace: ' + errObj.stack; } log.debug(errTyp, errMsg); return errMsg; } return { get, //put, //post, //delete: //doDelete } });