Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Jim Coyne
Kilo Patron
Part of the Tips 'N Tricks" series.

 

Just wanted to add a little something to my previous "TNT: Screenshots Help, but Code is Better" post.  Whenever you post some code to the Community site, please, please, please make sure when you paste it as code (see previous post), make sure it is properly indented so it is easier to read.  There's a "Format Code" button on most script fields in the platform that will properly indent the code for you:

 

find_real_file.png

 

You should use it all the time so your code is readable to you and your colleagues.  And when you paste it into a question/post on the Community, it makes it much easier for us to read and help you out.  This:

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord('cmn_skill_level');
    gr.addQuery('skill_level_type', current.skill.level_type);
    gr.orderBy('value');
    gr.query();
    if (gr.next()) {
        current.skill_level = gr.getUniqueValue();
    }
})(current, previous);

 

...is much easier to read than this:

 

(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('cmn_skill_level');
gr.addQuery('skill_level_type', current.skill.level_type);
gr.orderBy('value');
gr.query();
if(gr.next()) {
current.skill_level = gr.getUniqueValue();
}
})(current, previous);

 

And obviously, the longer the code is, the harder it is to read.