To check if a filealready exists, we can use a try and catch statement by checking if the errorcode returns "RCRD_DSNT_EXIST".
Below is a samplesnippet of code to check if a file exists or not.
functioncheck_if_file_exists(){
varfile_exists = true;
try{
var file = nlapiLoadFile('Images/test.jpg');
}
catch (e) {
nlapiLogExecution('DEBUG','ErrorCode:',e.getCode());
if(e.getCode()=="RCRD_DSNT_EXIST"){
file_exists = false;
}
}
if(file_exists){
// continue process for file
nlapiLogExecution('DEBUG','FileExists','continue with process');
} else {
// create a new file
nlapiLogExecution('DEBUG','File Does NotExist','create file before continuing');
}
}
DISCLAIMER: The sample code described herein isprovided on an "as is" basis, without warranty of any kind, to thefullest extent permitted by law. Netsuite Inc. does not warrant or guaranteethe individual success developers may have in implementing the sample code ontheir development platforms or in using their own Web server configurations.
Netsuite Inc. doesnot warrant, guarantee or make any representations regarding the use, resultsof use, accuracy, timeliness or completeness of any data or informationrelating to the sample code. Netsuite Inc. disclaims all warranties, express orimplied, and in particular, disclaims all warranties of merchantability,fitness for a particular purpose, and warranties related to the code, or anyservice or software related thereto.
Netsuite Inc. shallnot be liable for any direct, indirect or consequential damages or costs of anytype arising out of any action taken by you or others related to the samplecode.
No comments:
Post a Comment