
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-14-2020 06:11 AM
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:
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.
- 397 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for the tip :).
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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?