Hi,
Let's face it, SC's JS editor isn't the best thing that could happen to SC consultant, right?
Here's one of the "improvements" I had to use during one of the JS/WebServices projects.
Important: For this to work, You've got to place all the imported files/code on the SCServer and edit the files remotely (or mount the remote drive to Your environment)
OK, next, quick tutorial what to do with the code.Code:/* RCP2SCServiceImport */ /* local path to the js files, this is physically on SCServer system */ var localpath = "C:\\Peregrine\\ServiceCenter613_dev\\JS\\"; /* the last line of all the imported files, just a precaution */ var endLine = '/// Fin ----------------------------'; var pkgName = 'Custom JS Package'; // package name var msgs = []; var names = []; names.push({name:"RCP2SCServiceImport", exec:false}); /* exec parameter needs to be false for the Import script file!!! otherwise, this controls whether import should exec the JS. Next are the files to be imported from "localpath" dir. */ names.push({name:"RCP2SCService", exec:false}); names.push({name:"RCP2SCServiceUtils", exec:false}); names.push({name:"RCP2SCServiceTest", exec:false}); names.push({name:"RCP2SCServiceTest2", exec:true}); var sl = new SCFile('ScriptLibrary'); for(i=0;i<names.length;i++) { var file = readFile(localpath+names[i].name+".js",'b'); var slRC; /* actual import part, this adds new files and updates the old ones */ if(sl.doSelect('name = "'+names[i].name+'"') == RC_SUCCESS) { sl.script = file; slRC = sl.doUpdate(); } else { sl.script = file; sl.name = names[i].name; sl['package'] = pkgName; slRC = sl.doSave(); } /* due to some problems with national character encoding I had to implement a simple checkup after the import and before the execution */ var fLen = file.split('\n'); var slLen = sl.script.split('\n'); if(fLen.length != slLen.length) msgs.push([sl.name+ " - " +fLen.length + ":::" + slLen.length,2]); /* checking the "ending" line */ if(fLen[fLen.length-1] != endLine) msgs.push(["error reading the file: "+sl.name,3]); /* "compile" the file, another checkup */ if(slRC == RC_SUCCESS && (names[i].compile == undefined || names[i].compile)) compile("lib."+names[i].name,names[i].name); /* exec the file, if necessary */ if(slRC == RC_SUCCESS && names[i].exec) system.functions.jscall(names[i].name); } /* finally, print all gathered messages or "import ok ..." if file import OK */ if(msgs.length > 0) for(i=0;i<msgs.length;i++) msg(msgs[i][0],(msgs[i][1])?msgs[i][1]:1); else msg("import ok ...",1); function msg(str,klasa) { var ret = system.vars.$L_ret = 0; var vo = system.vars.$L_void = null; vo = system.functions.rtecall("msg",ret,str,(klasa)?klasa:1) } /// Fin ----------------------------
I hope this helps someone out there, I know it helped me, a lot actually.
- paste above into SC JS Editor, name the script "RCP2SCServiceImport" and save it.
- place the files to be imported on the remote/local system
- edit "names" array to match the filenames
- save once again
- open one of the files in external js editor (I prefer eclipse or scite :-) and do some hard, coding work
- every time you need to check how SC handles the changes, exec the import file
- you're done!




Reply With Quote


Bookmarks