Server Code

From TeamServer ER/Studio
Jump to: navigation, search

Go Up to Creating an App

The Server Code menu on the Apps page is where you add the script files to run in your app.

To create a new Server Code:

  1. Click the New File button.
  2. In the New File window that appears, choose a name for your Server Code File and click Save.
  3. Highlight the New File you have created by clicking the name of your new file.
  4. To save any script that you enter in to the Server Code window, choose the Save button.

The following script is a function to add the Steward of your choosing to all terms.

function addStewardToAllTerms(stewardId) {
    var added = 0;
    var error = 0;
    var already = 0;
    var terms = TeamServer.terms.list();
    for ( var i=0; i<terms.size(); i++ ) {
        var term = terms.get(i);
        try {
            if ( !(term.stewards.get(stewardId) === null) ) {
                already++;
            }
        } catch(err) {
            var result = term.stewards.add(stewardId);
            if (result.result == "OK") {
                added++;
            }
            else {
                error++;
                println(result.message);
            }
        }
    }
    println( "Add steward " + stewardId + " to all terms: added " + added + ", already steward " + already + ", errors " + error);
}
addStewardToAllTerms("2");

It is possible to copy and paste this script in to your server code window. Changing the final line to instruct the function to work with your required steward. The example above uses '2', you may wish to change this to addStewardToAllTerms("1"); for Admin.


See Also