Return NetSuite file contents by NetSuite file internal ID.
/** | |
* @NApiVersion 2.0 | |
* @NScriptType Restlet | |
* @NModuleScope SameAccount | |
* @Author Charles.Bastian | |
* @Created 2019-03-13 | |
* @ScriptName REST_Query_File_Contents_by_InternalID | |
* @Filename REST_Query_File_Contents_by_InternalID.js | |
* @ScriptID customscript_rest_get_file_contents | |
* @Production | |
* @FileID | |
* @InternalURL | |
* @ExternalURL | |
* @SearchURL | |
* @SandBoxQA | |
* @FileID | |
* @InternalURL | |
* @ExternalURL N/A | |
* | |
* @modifications | |
* Date Author Version Remarks | |
* 2019-03-13 Charles.Bastian v1.3.13-1 Created | |
* | |
* | |
*/ | |
| |
define(['N/search','N/record','N/file'],function(search,record,file){ | |
/** | |
* Function called upon sending a GET request to the RESTlet. | |
*/ | |
function doGet(requestParams){ | |
log.debug('in doGet',JSON.stringify(requestParams.custparamfileNSID)); | |
if(requestParams.custparamfileNSID!==undefined){ | |
if(requestParams.custparamfileNSID!=''){ | |
return findFileByInternalID(requestParams.custparamfileNSID); | |
}else{ | |
return JSON.stringify({'ERROR[E0]':'No NetSuite internal ID value received.'}); | |
} | |
}else{ | |
return JSON.stringify({'ERROR[E1]':'Missing fileNSID parameter'}); | |
} | |
} | |
| |
function findFileByInternalID(nsID){ | |
var respObj={}; | |
var fileObj=file.load({id:nsID}); | |
try{ | |
if(fileObj){ | |
log.debug('fileObj',JSON.stringify(fileObj.getContents())); | |
respObj={'fileObj':fileObj,'fileContents':fileObj.getContents()}; | |
}else{ | |
respObj=JSON.stringify({'ERROR[E2]':'No File with NetSuite internal ID: '+nsID+' found.'}); | |
} | |
log.debug('respObj',JSON.stringify(respObj)); | |
}catch(E3){ | |
return JSON.stringify({'ERROR[E3]':JSON.stringify(E3.message)}); | |
} | |
return JSON.stringify(respObj); | |
} | |
return{ | |
'get':doGet | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment