Ashley Snyder1
Giga Guru

I'm sure other articles have been written about this before, but as I look at the community each day I see the same kind of posts over and over again. Most of the time, when I click on a question that has a huge blob of unformatted code without any comments or context by the poster, I blaze right on by it and go to the next question.

For example:


var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

Formatting like this makes it incredibly hard for anyone to decipher code quickly and provide an answer. Please remember to format code by clicking:

 find_real_file.png

Here's an example of formatted code with context on what the code is trying to do:

/* I'm trying to do an encoded query on the incident table to look for incidents that are active, 
and the category is software or hardware. */

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

var gr = new GlideRecord('incident');
var strQuery = 'active=true';
strQuery = strQuery + '^category=software';
strQuery = strQuery + '^ORcategory=hardware';
gr.addEncodedQuery(strQuery);
gr.query();

This assists in allowing others to read the code in a clear and concise way (just like in our instances ^_^) to answer questions.  Also, it looks great, and four years from now when someone reads the question on community as they're having the same problem, they can understand the question and the solution very quickly.

Comments
Pranav Bhagat
Kilo Sage

Thanks for the tip :).

Maik Skoddow
Tera Patron
Tera Patron

Even worse are questions with attached screenshots.

Can someone please tell the users that it is possible to paste screenshots directly into the editor so that they are displayed inline?

Version history
Last update:
‎08-14-2020 06:11 AM
Updated by: