Blogs

JavaScript Tips and Tricks: Aggregates...

A few weeks ago I was talking with one of our customers (I'll call him Joe) who had just finished writing a script that created a little report of how many items of each type were in his CMDB. Joe was quite happy with his script except that it took a long time to run. Here's what Joe had written:

var gr = new GlideRecord('cmdb_ci');
gr.orderBy('sys_class_name');
gr.query();

var name = '';
var count = 0;
while (gr.next()) {
    var thisName = '' + gr.getValue('sys_class_name');
    if (thisName == name)
        count++;
    else {
        if (name != '')
            gs.log(thisName + ': ' + count);
        name = thisName;
        count = 1;
    }
}
gs.log(name + ': ' + count);

Joe did this the hard, slow way – there's a much easier way, one that exploits the capabilities of the database that underlies every Service-now.com instance.

Firefox Add-on & the magic number

OLUGFirst off I wanted to say, wow. Great to see we finally hit the 100 mark on the members of the Ohio LUG of Service-Now.com. I look forward to talking with everyone about the experience of the user group at Knowledge '10 next month.

 

JavaScript Tips and Tricks: The Three Flavors of Strings...

A string is a string, right? Ah, if only 'twas so!

JavaScript all by itself has two different kinds of strings: there's the primitive “string” (with a lower case ‘s’) and then there's the “String” class (which you can create instances of. For example:

var x = 'this is a primitive string';
var y = new String('this is a String instance');
gs.log(x + ': ' + typeof x);   // this will show typeof 'string'
gs.log(y + ': ' + typeof y);   // this will show typeof 'object'

In the code above, the variable x has a primitive string and the variable y has a String instance. In practical usage, the two behave nearly identically – with the obvious exception of the result of the typeof operator.

But what about the third flavor?

JavaScript Tips and Tricks: The Two Flavors of Undefined...

In JavaScript, “undefined” means two distinctly different things:

  1. A property that doesn't exist.
  2. A property that has the “undefined” value assigned to it.

Huh? Aren't those two ways of saying the same thing? Well…not exactly, and the differences can lead to some unexpected results. Consider this example:

Close task from an email

I want to know how you can put a Close Task Link on an email notification that gets sent out to the group Want to have ability for users to click on Close from the email and have that catalog task close with the email response.

JavaScript Tips and Tricks: What's Up with Packages?

Several customers have asked me about the odd-looking “Packages...” invocations they see sometimes in server-side JavaScript (like business rules or script includes). For instance, you might find a piece of code like this:

var a = getCITypes();
JSUtil.logObject(a);

function getCITypes() {
    var hs = new Packages.java.util.HashSet();
    var gr = new GlideRecord('cmdb_ci');
    gr.query();
    while (gr.next())
        hs.add('' + gr.sys_class_name);
    var it = hs.iterator();
    var answer = [];
    while (it.hasNext())
        answer.push('' + it.next());
   return answer;
}

This code will return (very inefficiently!) a list of all the types of CIs that are actually in your CMDB. But what the heck is that funny-looking “Packages.java.util.HashSet()” all about?

JavaScript Tips and Tricks: What's Up with the Functions?

In a conversation I had with a customer the other day, she asked me why she saw so many examples of business rules written in functions, like this:

doImportantStuff();

function doImportantStuff() {
    var x = 15;
    var y = 22.3;
    var z = Math.pow(15, 22.3);
    current.answer = z;
}

Well, leaving aside the questionable wisdom of ever raising 15 to the 22.3rd power, that's a good question – and the answer lies both in the nature of JavaScript and of the Service-now.com platform:

Work Flow Bug

A member of the Texas User Group has discovered a bug in work flow that I wanted to make you aware of. Apparently if you make more than 1 change to a work flow update set then it corrupts the workflow. Srv Now knows about this and there is some work around or fix but thought this might be useful information to the user community so that others can benefit. Thanks Stephanie for the information.

Service-now.com Guru

Here's a site to bookmark and subscribe to: http://www.servicenowguru.com/

Check it out.

Terry Brown

Blue Cross show and tell recording

Want to get some insight on Service Now and see an amazing instance?

Blue Cross Blue Sheild Minnesota was nice enough to show theirs off and allowed a recording of it too. So if you missed this, watch it here, post comments etc.

If you'd like to volunteer to host, I'd love to hear from you. Again, my e-mail: mattberan [at] gmail [dot] com

PASSWORD: vug123

https://ammd.webex.com/ammd/ldr.php?AT=pb&SP=MC&rID=14069727&rKey=358113...

Syndicate content