Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 7 of 7

Thread: Tired of SC JS Editor? Might want to try this ...

  1. #1
    Senior Member mateuszk's Avatar
    Join Date
    Nov 2006
    Posts
    302

    Lightbulb Tired of SC JS Editor? Might want to try this ...

    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)
    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 ----------------------------
    OK, next, quick tutorial what to do with the code.

    1. paste above into SC JS Editor, name the script "RCP2SCServiceImport" and save it.
    2. place the files to be imported on the remote/local system
    3. edit "names" array to match the filenames
    4. save once again
    5. open one of the files in external js editor (I prefer eclipse or scite :-) and do some hard, coding work
    6. every time you need to check how SC handles the changes, exec the import file
    7. you're done!
    I hope this helps someone out there, I know it helped me, a lot actually.

  2. #2
    Member
    Join Date
    Feb 2002
    Location
    Phoenix, AZ
    Posts
    34

    Default

    Um, what exactly does this do? I don't understand....

  3. #3
    Senior Member benvargas's Avatar
    Join Date
    Apr 2005
    Location
    San Diego, CA USA
    Posts
    194

    Default

    Sounds like it will read javascript files written in another IDE with more advanced functionality (formatting, auto-completion of javascript functions, etc.)... and then imports them into the ScriptLibrary for you (with better formatting/wrapping).

    Haven't tried it though, just glanced at the code and quickly read the description. Some IDEs are much easier to develop in (at least in terms of common javascript methods/functions, auto bracketing, etc).

  4. #4
    Senior Member glg's Avatar
    Join Date
    Aug 2004
    Location
    Chicago, IL, USA
    Posts
    715

    Default

    Wouldn't copy/paste work fine for something like that?

  5. #5
    Senior Member benvargas's Avatar
    Join Date
    Apr 2005
    Location
    San Diego, CA USA
    Posts
    194

    Default

    I'm wondering if it doesn't wrap right or compile right depending on the IDE? Hopefully he'll elaborate a bit

  6. #6
    Senior Member mateuszk's Avatar
    Join Date
    Nov 2006
    Posts
    302

    Default

    Wouldn't copy/paste work fine for something like that?
    Yes, it would. That's exactly how I was doing it before.
    I had to work on WebService<->SC integration project that had A LOT of JS code, spanning between 20+ files.
    Now, try to handle this much copy/paste and stay focused on changes in the code, good luck

    I'm wondering if it doesn't wrap right or compile right depending on the IDE?
    I'm not sure I'm getting your question right, I'm not English native.
    Please correct me if I got it wrong.

    The way it works on my setup:
    1. place all the files you want to import in the catalog
    2. paste the import script into empty SL window, name it, add, execute.
    3. next, I worked with one SC ScriptLibrary window open (the "import" script) and had to exec it every once in a while (to check errors, test functionality etc.)

    For me, having an SC client window open was a must as I had to check
    the behavior of SC modules against WS queries/replies I was getting (saving/opening an incident/task etc.).
    I believe there's an easy way to make it work without SC client but this would serve no purpose in my case.

    In case you're referring to actual "wrapping of the line" in the code, no problem there.
    Had some problems with national chars during import but I solved it by moving all the messages to scmessage and using "the old proper SC way"
    of getting the message. The code had to be "nationals clean" for the import to work.

  7. #7
    Senior Member benvargas's Avatar
    Join Date
    Apr 2005
    Location
    San Diego, CA USA
    Posts
    194

    Smile

    Quote Originally Posted by mateuszk View Post

    I'm not sure I'm getting your question right, I'm not English native.
    Please correct me if I got it wrong.
    Yes, i was simply wondering if copying and pasting wasn't wrapping correctly - so I was just trying to speculate as to why you wouldn't just copy and paste. But, you cleared that up by saying you had 20+ JS files to load in.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts